gpt4 book ai didi

javascript - url 的模态对话框不起作用?

转载 作者:行者123 更新时间:2023-12-02 15:50:51 29 4
gpt4 key购买 nike

抱歉,这让我抓狂,但是当我将按钮切换到链接时,我的模式对话框没有显示。基本上对于这个功能(抱歉,我不得不取出公司敏感数据,所以一些代码丢失了,但仍然有效)我只是希望编辑器放入一个带有 id 或类的链接,该链接不起作用,但地址打开一个对话框,其中包含地址 url。

我可以使用按钮来实现此功能,但这不适用于下面的链接和代码。他们还手动将链接输入到 p-tag 中,并想知道是否可以通过 href 捕获它。

$(function() {
var dialog, form,


tips = $( ".validateTips" );


function addUser() {
var valid = true;
allFields.removeClass( "ui-state-error" );

valid = valid && checkLength( name, "username", 3, 16 );
valid = valid && checkLength( email, "email", 6, 80 );
valid = valid && checkLength( password, "password", 5, 16 );

valid = valid && checkRegexp( name, /^[a-z]([0-9a-z_\s])+$/i, "Username may consist of a-z, 0-9, underscores, spaces and must begin with a letter." );
valid = valid && checkRegexp( email, emailRegex, "eg. ui@jquery.com" );
valid = valid && checkRegexp( password, /^([0-9a-zA-Z])+$/, "Password field only allow : a-z 0-9" );

if ( valid ) {
$( "#users tbody" ).append( "<tr>" +
"<td>" + name.val() + "</td>" +
"<td>" + email.val() + "</td>" +
"<td>" + password.val() + "</td>" +
"</tr>" );
dialog.dialog( "close" );
}
return valid;
}

dialog = $( "#dialog-form" ).dialog({
autoOpen: false,
height: 300,
width: 350,
modal: true,

});

form = dialog.find( "form" ).on( "submit", function( event ) {
event.preventDefault();
addUser();
});

$( "#create-link" ).a().on( "click", function(e) {
e.preventDefault();
dialog.dialog( "open" );
});
});



<div><a href="https://xyz" id="create-link">Perma-link</a></div>
<div id="dialog-form" title="Link Address">
<p class="validateTips">https://xyz</p>
</div>

注意 - 我完全理解在模式框中捕获链接很奇怪,但我们必须这样做,因为 vendor 不会在 url 中显示完整的事件链接。因此,当我们的用户尝试共享页面时,他们会在浏览器中复制 URL,这不会将其他用户带到任何地方。此处的链接将他们带到永久页面。我知道这很愚蠢,但很有必要。

最佳答案

当您使用 jQuery 选择器查找元素时,它会返回一个 jQuery 对象,您可以在该对象上调用 jQuery 定义的方法。

在您的代码中,您有:

$( "#create-link" ).a().on( "click", function(e) {
e.preventDefault();
dialog.dialog( "open" );
});

$("#create-link") 返回的对象是 html 中 a 标记的 jQuery 对象。您只能对该对象调用 jQuery 方法。据我所知,a() 方法在 jQuery 或 jQuery UI 中尚未定义。删除它。

就链接本身而言,添加链接然后阻止点击链接的 Action 是没有意义的。根据以下评论,我猜您不理解这些要求:

the UI guys wanted me to hand it over as a link. So the last part of this was moving the button to a link and then making the href automatically populate the validateTips section

这对我来说就像他们希望你向用户提供一个链接。

关于javascript - url 的模态对话框不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31864867/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com