gpt4 book ai didi

JQuery 未在单击时运行

转载 作者:行者123 更新时间:2023-12-01 06:27:52 26 4
gpt4 key购买 nike

早上好,伙计们,我正在尝试学习 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com