我尝试通过onclick
有jquery功能:
function handleit(cId, anotherId) {
var campaingID = cId;
var another = anotherId;
var post = "action=remove&campaign_id=" + campaingID + "&anotherid=" + another;
$.ajax({
type: "post",
url: "ajax/phphandler.php",
data: post,
cache: false,
success: function(html) {
$('#ready').html(html);
}
});
return false;
}
并且有onclick
代码
<td><input class="btn btn-default" type="submit" data='.$row2['campaign_id'].' value="submit" onclick="return handleit("'.$row2['campaign_id'].'","test")"></td>
渲染html
<td><input class="btn btn-default" type="submit" data=43 value="submit" onclick="return handleit(" 43","test")"></td>
答案 0 :(得分:0)
问题是您的HTML看起来像:
<input class="btn btn-default" type="submit" data=foo value="submit"
onclick="return handleit("campaign_id","test")">
^ ^ ^ ^
定义属性时,不能在"
内嵌套"
。 HTML需要看起来像:
<input class="btn btn-default" type="submit" data=foo value="submit"
onclick="return handleit('campaign_id','test')">
^ ^ ^ ^
你如何实现这取决于你正在使用的服务器端语言,但可能涉及转义引号:
<td>
<input class="btn btn-default" type="submit"
data="'.$row2['campaign_id'].'" value="submit"
onclick="return handleit(\''.$row2['campaign_id'].'\',\'test\')"
</td>