JQuery 未在单击时运行

标签 jquery

早上好,伙计们,我正在尝试学习 jquery,从我从 js 了解到的情况来看,这应该可以工作,但它不能...基本上 onclick 提交按钮,它应该更改内部 html。有更多经验的人有什么想法吗?

jquery:

$(function() {
    $("#submitButton").click(function(){
        reply();
    })
});

function reply(){
 document.getElementById("#progressBar").innerHTML = "worksbro";
}

html:

<button type="button" id="submitButton">Submit</button>

如果我没记错的话,这应该可行。它应该更改 progressBar 但 onclick 不执行任何操作

为了消除一些困惑:

<div id = "progressBar"></div>

所有代码:

<!DOCTYPE html>
<html>
<head>
<script src="theJS.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js" type="text/javascript"></script>

<script type="text/javascript">

$(function() {
    $("#submitButton").click(function(){
        reply();
    })
});

function reply(){
 $("progressBar").html("worksbro");
}

</script>


<title>
One neat van page
</title>
</head>
<body>
<div id="tableone">
<?php
//connect to db
include 'connect.php';

//start the table float left
cho '<table>';
echo '<tr><td style="background-color:#03899C; color:white; text-align:center;">Driver</td>
<td style="background-color:#03899C; color:white; text-align:center;">Van</td></tr>';

//lets get dem drivers and vans
//actually just the vans, realistically. 
$sql= 'SELECT *
FROM Vans';

//make a table float let with driver name and an info(keep it simple)
foreach($conn->query($sql) as $row) {
  echo '<tr id="'.$row['Owner'].'" style="cursor:pointer;" onClick="more(this.id)">';
    echo "<td style=\"background-color:#FFFC00;\"><a href=#>".$row['Owner']."</a></td>";
    echo "<td style=\"background-color:#FFFC00;\">".$row['Year']." ".$row['Make']." ".$row['Model']."</td>";
  echo '<tr>';      
}

echo '</table>';
?>
</div>

<div id="more">
<div id="edit"></div>
<h1 id="van"><u>More Info</u></h1>
<div id="vanList">
</div><!--end vanList-->
</div>

<div id = "progressBar">
<progress value="0" max="100"></progress>
</div>

<div id="innactive">
<h3>Innactive Vans</h3>
<table>
<?php
//connect to the database
include 'connect.php';
//get inactive vans
//my brain is mush right now, so bear with me...
$sql = "SELECT *
FROM Vans
";



foreach($conn->query($sql) as $row) {
if (!empty($row['Innactive'])){

echo '<tr><td style="background-color:#03899C; color:white; text-align:center;">Driver</td>
<td style="background-color:#03899C; color:white; text-align:center;">Van</td></tr>';

  echo '<tr id="'.$row['Owner'].'" style="cursor:pointer;" onClick="more(this.id)">';
    echo "<td style=\"background-color:#FFFC00;\"><a href=#>".$row['Owner']."</a></td>";
    echo "<td style=\"background-color:#FFFC00;\">".$row['Year']." ".$row['Make']." ".$row['Model']."                    </td>";
  echo '</tr>';
}
}



?>




</div>
</body>
</html>

最佳答案

现在我们有了完整的代码,问题就清楚了... HTML 中没有#submitButton –

“对不起,我的错,按钮就在那里,它是根据 ajax 请求通过 php 创建的”

解决方案,需要 future 的事件

$(function() {
    $(document).on('click', '#submitButton', function(e){
        e.preventDefault();
        $('#progressBar').html("worksbro");
    })
});

关于JQuery 未在单击时运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14732307/

相关文章:

javascript - 如何限制用户在文本区域只能输入250个字?

Jquery UI - 允许 droppable 具有可阻止的 div

javascript - 如何使一列始终突出显示

javascript - 我可以在处理事件时依赖 attach order 吗?

c# - 每当在aspx页面的文本框中键入内容时,我都想隐藏标签

javascript - 如何在不使用 jQuery 的情况下添加点击处理程序

javascript - 用于扩展框的 float 箭头(jQuery)

php - PHP 注册表出现错误

jquery - 将函数应用于动态生成的元素

javascript - 使用轮播滑动图像