为什么我的Javascript不能在jsp页面中工作
Why is my Javascript not work in jsp page?
我创建了一个函数来检查第一个单选按钮,但我的javascript不起作用。当我在jsfiddle中使用它时,它工作得很好,但当我在jsp页面中尝试时,它不再工作了。有人能告诉我我做错了什么吗?我使用struts 1,不使用任何jquery库。
这是我的代码:
document.querySelectorAll('[name=radioButton]')[0].checked = true;
<table id="tabledata" style="width: 80%" border=1>
<tr>
<th></th>
<th>Name</th>
<th>Code</th>
</tr>
<tr>
<td><input type="radio" name="radioButton"></td>
<td>122222222222222</td>
<td>4444444444444444 </td>
</tr>
<tr>
<td><input type="radio" name="radioButton"></td>
<td>122222222222222</td>
<td>4444444444444444 </td>
</tr>
<tr>
<td><input type="radio" name="radioButton"></td>
<td>122222222222222</td>
<td>4444444444444444 </td>
</tr>
<tr>
<td><input type="radio" name="radioButton"></td>
<td>122222222222222</td>
<td>4444444444444444 </td>
</tr>
</table>
这是我的jsp代码:
<html:form action="/Showdata">
<div class="loaddata">
<table id="tabledata" style="width: 80%" border=1>
<tr>
<th></th>
<th>Name</th>
<th>Code</th>
</tr>
<logic:iterate id="listEmp" name="ShowdataForm" property="listEmp">
<tr>
<td><input type="radio" name="radioButton"></td>
<td><bean:write name="listEmp" property="name"/></td>
<td><bean:write name="listEmp" property="code"/> </td>
</tr>
</logic:iterate>
</table>
</div>
</html:form>
好吧,这个问题的框架不正确。我在javascript代码中发现了一些错误。
$(document).ready(function() {
//$(function() {remove this
alert("Hello! I am an alert box!!");
$("input:radio[name='radioButton']:visible:first").attr('checked', 'checked');
}//why do you have a curly brace here?
);
$(function() {
$('#tabledata tr').click(function() {
$(this).find('tr input:radio').prop('checked', true);
})
//});
});
如果你想在选中单选按钮时做点什么,试试这个
$('input:radio[name="radioButton"]').change(
function(){
if (this.checked && this.value == 'Yes') {
// called on checking an <input>, not
// on un-checking it.
}
});
$(document).ready(function() {//put a block of code in here to run it as soon as document loads.
alert("page loaded");
//no need of putting a $(function(){ }); here again
}
相关文章:
- JavaScript没有'JSP页面重定向后无法工作..任何解决方案
- window.open无法在显示pdf的jsp页面中工作
- 无法让jQuery插件timepicker在jsp页面中工作
- 使用 href=“#” JQuery 工作,但使用 href=“page.jsp” 不起作用
- JQuery Ajax 不能在带有 Struts 的 JSP 中工作
- 如何在使用弹簧框架工作时提供JSP页面的URL以打开WEB-INF文件夹中的弹出窗口
- JSP 无法与 PrintWriter 正常工作
- javascript代码在jsp中没有按预期工作
- 为什么我的Javascript不能在jsp页面中工作
- Jquery日期拾取器,即使另一个具有共享导入的JSP工作也没有响应
- 在我的jsp代码中出现了一些奇怪的东西,x++不能工作
- 为什么javascript自动提交不工作在我的jsp页面
- JSP方法在javascript方法中不能正常工作
- 使用Jquery的AJAX不能跨JSP页面工作
- javascript重定向到JSP不工作(使用Spring MVC)
- Facebook javascript SDK共享版本从属性文件到jsp不工作[webapp]
- JSP Servlet在使用IF块后不工作
- jQuery不能在JSP中工作
- 使用标签提交表单在JSP不工作
- 如何将JSP页面的一部分导出到excel工作表