gpt4 book ai didi

javascript - jQuery 模式对话框使用加载已包含 jQuery 代码(自动完成)内容的表单页面?

转载 作者:行者123 更新时间:2023-11-28 02:53:02 25 4
gpt4 key购买 nike

我在动态生成的网页中有一个表单,我想使用 jQuery UI 模式对话框显示它。

当我的表单未嵌入 jQuery UI 本身时,我在上一篇文章中提出的解决方案有效:jQuery UI modal dialog form using remote content .

远程表单已包含 jQuery 函数的方式:自动完成。

如何解决这个问题?

<body>
<div>
<table cellpadding="0" cellspacing="0" border="0" class="display" id="example">
<thead>
<tr>
<th>software </th>
<th>script</th>
<th>exec_type</th>
<th>run_status</th>
<th>test_result</th>
<th>review_status</th>
<th>priority</th>
<th>author</th>
<th>creation date</th>
<th>update date</th>
<th>edit</th>
</tr>
</thead>

<tfoot>
<tr>
<th>software </th>
<th>script</th>
<th>exec_type</th>
<th>run_status</th>
<th>test_result</th>
<th>review_status</th>
<th>priority</th>
<th>author</th>
<th>creation date</th>
<th>update date</th>
<th>edit</th>
</tr>
</tfoot>

<tbody>

</tbody>



</table>

</div>


<script type="text/javascript" charset="utf-8">

$('td').click( function(){$("#formContainer").load("myform.html", function() {
var container = $(this);
container.dialog({
modal: true
})
.find("form").submit(function() {
container.dialog("close");
return false;
});
});

})
;
</script>



</body>

form.html 看起来像这样:

    <script type="text/javascript" charset="utf-8">

(function($) {
$.widget("ui.combobox", {
_create: function() {
var self = this;
var select = this.element.hide();
var input = $("<input>")
.insertAfter(select)
.autocomplete({
source: function(request, response) {
var matcher = new RegExp(request.term, "i");
response(select.children("option").map(function() {
var text = $(this).text();
if (this.value && (!request.term || matcher.test(text)))
return {
id: this.value,
label: text.replace(new RegExp("(?![^&;]+;)(?!<[^<>]*)(" + $.ui.autocomplete.escapeRegex(request.term) + ")(?![^<>]*>)(?![^&;]+;)", "gi"), "<strong>$1</strong>"),
value: text
};
}));
},
delay: 0,
change: function(event, ui) {
if (!ui.item) {
// remove invalid value, as it didn't match anything
$(this).val("");
return false;
}
select.val(ui.item.id);
self._trigger("selected", event, {
item: select.find("[value='" + ui.item.id + "']")
});

},
minLength: 0
})
.addClass("ui-widget ui-widget-content ui-corner-left");

// This line added to set default value of the combobox
input.val(jQuery("#"+select.attr("id")+" :selected").text() )

$("<button>&nbsp;</button>")
.attr("tabIndex", -1)
.attr("title", "Show All Items")
.insertAfter(input)
.button({
icons: {
primary: "ui-icon-triangle-1-s"
},
text: false
}).removeClass("ui-corner-all")
.addClass("ui-corner-right ui-button-icon")
.click(function() {
// close if already visible
if (input.autocomplete("widget").is(":visible")) {
input.autocomplete("close");
return false;
}
// pass empty string as value to search for, displaying all results
input.autocomplete("search", "");
input.focus();
return false
});
}
});

})(jQuery);

$(function() {
$("#id_software").combobox();
$("#id_script").combobox();

});



</script>


<body>
<div>
<form action="/followup/forms/runs/8/" method="post">
<p><label for="id_software">Software:</label> <select name="software" id="id_software">

<option value="">---------</option>
<option value="1" selected="selected">AS_1500_211</option>
<option value="2">AS_1500_212</option>
<option value="3">AS_1500_213</option>
<option value="4">AS_1500_214</option>
</select></p>
<p><label for="id_script">Script:</label> <select name="script" id="id_script">
<option value="">---------</option>
<option value="1">OBJECT__1_TC1</option>

<option value="2">OBJECT__2_TC1</option>
<option value="3">OBJECT__2_TC2</option>
<option value="4">OBJECT__3_TC1</option>
<option value="5">OBJECT__3_TC2</option>
<option value="6">OBJECT__4_TC1</option>
<option value="7">OBJECT__4_TC2</option>
</select></p>
<input type="submit" value="Submit" />
</form>

</div>
</body>

最佳答案

所以我知道这是一篇旧帖子,但我在这里没有看到答案。我相信你需要的是一个名为 livequery 的 jquery 插件。它将允许您将 jquery-ui 功能添加到表中,并通过等待它们存在于 dom 中来动态加载。

当前:

$(function() {
$("#id_software").combobox();
$("#id_script").combobox();
});

使用 livequery:

$(function() {
$("#id_software").livequery(function() { $(this).combobox(); });
$("#id_script").livequery(function() { $(this).combobox(); });
});

关于javascript - jQuery 模式对话框使用加载已包含 jQuery 代码(自动完成)内容的表单页面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3359352/

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