我想要做的是获得与单击以下提交按钮相同的结果。
<input id="submit_http:" class="add_submit" type="button" onclick="return dex.forms.form_ajax_submit(this,function(res) { alert('posting failed'); },function(res) { alert('posting success'); });" value="Next" name="submit_http:">
我试着这样做:
$('.NextButton').click(function () {
dex.forms.form_ajax_submit(document.getElementsByName('submit_http:'),
function(res) {
alert('posting failed');
},
function(res) {
alert('posting success');
});
});
但看起来 document.getElementsByName 没有返回相同的结果 作为提交按钮“this” 我该如何解决这个问题?
最佳答案
您犯的唯一实际错误是使用函数 document.getElementsByName
,因为它返回一个元素数组(如复数所示)。您需要的是单个元素。
使用以下方法访问数组的第一个元素:
document.getElementsByName('submit_http:')[0]
或者使用已经推荐的更精确的函数:
document.getElementById('submit_http:')
关于javascript - 在不使用单词 'this' 的情况下在 javascript 中获取 'this' 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9499517/