gpt4 book ai didi

php - 在选择时将 PHP 链接到 Mootools

转载 作者:可可西里 更新时间:2023-10-31 23:34:41 24 4
gpt4 key购买 nike

如果我从下拉菜单中选择一个值(下拉菜单是从数据库中获取的),我将如何填写我的表单的框?不知何故,在我的 javascript 中,我需要连接到函数,因为涉及到不同的表与表单字段。

问题

是否需要使用 $field name 设置字段?

if(document.id('LoadExtension') && document.id('ExtensionResponse')) { // id of select box
var sel = document.id('LoadExtension'); // ser select box as var.
sel.addEvent('change', function(chg) { // add change event to select box.
if(sel.getSelected().get('value') != '') { // on change if selected value is not empty.
new Request.HTML({
url : 'http://domain.co.nz/index.php?extension='+ sel.getSelected().get('value'),
onRequest: function() {

},
onComplete: function(r1, r2, html, js) {
document.id('ExtensionResponse').set('html', html);
}
}).send();
}
});

上面的代码被设置为从 url: 框中的另一个文档获取,但我想在一个页面中完成。

最佳答案

对于您的代码:

http://www.jsfiddle.net/dimitar/TXHYg/4/

(function() {
// anon closure for scope purposes of local vars.

// cache selectors used repeatedly into local vars.
var sel = document.id('LoadExtension'), resp = document.id('ExtensionResponse');

// if they are in the dom...
if (sel && resp) {
// ... then attach event listener.
sel.addEvent('change', function(event) {
// this == sel.
var value = this.get("value"); // cache getter.

if (value === '') {
return false; // do nothing if not selected/
}

// otherwise, it will run the request
new Request.HTML({
method: "get", // or post.
data: {
extension: value // etc etc, can add more object properties and values
},
url: 'http://domain.co.nz/index.php',
onComplete: function(r1, r2, html, js) {
resp.set('html', html);
}
}).send();
});
} // end if
})(); // end closure.

你真的应该看看一些教程和示例以及 Request 和 Request.HTML/JSON/JSONP 的文档

一个示例,类似于您的示例,它通过其 echo 测试服务为 jsfiddle 工作(模拟响应的数据对象略有不同)

http://www.jsfiddle.net/dimitar/TXHYg/3/

关于php - 在选择时将 PHP 链接到 Mootools,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4789238/

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