点击发送按钮后。我必须将这些参数传递给函数,但它没有按预期工作。如果您了解它,请帮助。下面是按钮和功能...
$pm_ui .= '<button type="submit" id="pmBtn" onclick="postPm(\''.$u.'\',\''.$log_username.'\',\'$pmsubject\',\'$pmtext\')">Send</button>';
function postPm(tuser,fuser,subject,ta){
var data = _(ta).value;
var data2 = _(subject).value;
if(data == "" || data2 == ""){
alert("Fill all fields");
return false;
}
_("pmBtn").disabled = true;
var ajax = ajaxObj("POST", "php_parsers/pm_system.php");
ajax.onreadystatechange = function() {
if(ajaxReturn(ajax) == true) {
if(ajax.responseText == "pm_sent"){
alert("Message has been sent.");
_("pmBtn").disabled = false;
_(ta).value = "";
_(subject).value = "";
} else {
alert(ajax.responseText);
}
}
}
ajax.send("action=new_pm&fuser="+fuser+"&tuser="+tuser+"&data="+data+"&data2="+data2);
}
但每当我点击“发送”按钮时,它就不会触发功能 代码如下。如果我遗失了什么,请帮助我把注意力集中在那里..(按钮没有响应任何事情......)
答案 0 :(得分:-2)
好的,我做了这个测试并且有效
<?php
$u = 'u';
$log_username = 'log_username';
$pmsubject = 5;
$pmtext = 4;
echo '<button type="submit" id="pmBtn" onclick="postPm(\''.$u.'\',\''.$log_username.'\','.$pmsubject.','.$pmtext.')">Send</button>';
?>
<script>
var postPm=function (tuser,fuser,subject,ta){
console.log(tuser);
console.log(fuser);
console.log(subject);
console.log(ta);
}
</script>
我希望它有所帮助