我在页面上加载了一个表单,使用以下javascript在父页面上加载onclick事件。它被加载到DIV中。
function loadContent(elementSelector, sourceURL) {
$(""+elementSelector+"").load("http://myurl.co.nz/"+sourceURL+"");
}
然后在另一个点击事件(在新表单中)中,表单中的一个字段填充了随机密码。
<label>Password:</label><input type="text" name="password" /><br/>
<input type="button" value="Generate Password" onClick="genPwd()"/>
function genPwd(){
$.post("rpc.php", {
method: "genPwd"
},
function(data,textstatus){
document.form.password.value = data.message;
}, "json");
}
页面上的所有javascript都包含在加载时。
Chrome和FF很好用,但IE8说document.form.password不存在,我假设因为它不在原始页面中。有什么方法吗?
干杯
答案 0 :(得分:3)
不推荐使用AFAIK document.form
。您可以使用此跨浏览器解决方案:
$('#passwordFieldId').val(data.message);