嗨我正在尝试编写一个jquery代码,在点击时会显示一个popwindow并且其中有单选按钮。 这是我的jquery代码:
$("#myPopup").ready(function() {
var popUpList = $('<div><input type="radio">A<br><input type="radio">B<br>
<input type="radio">C</div>');
showPopUpButton.click(myFunction() {
popUpList.dialog();
});
});
以下是相应的弹出式呼叫代码:
<li class="header_navigation_list">
<div data-role="main" class="header_navigation_link">
<a href="#myPopup" data-rel="popup" class="ui-btn ui-btn-inline ui-corner-all">Show Popup</a>
<div data-role="popup" id="myPopup">
<button id ="showPopUpButton" onclick="myFunction()">Click me</button>
<p>This is a simple popup.</p>
</div>
</div>
<span>|</span>
</li>
.js页面上的jquery代码将错误抛出为“此行的多个标记(期望FunctionExpressionHeaderName)”。似乎我没有在jquery中正确调用函数。有人可以就此提出建议。 TIA
答案 0 :(得分:1)
您需要删除popUpList
var中的回车符,将#showPopUpButton
jquery对象与$.on()
一起使用,然后删除HTML中的onclick
处理程序。
$("#myPopup").ready(function() {
var popUpList = $(
'<div><input type="radio">A<br><input type="radio">B<br><input type="radio">C</div>'
);
$('#showPopUpButton').on('click',function() {
popUpList.dialog();
});
});
&#13;
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
<li class="header_navigation_list">
<div data-role="main" class="header_navigation_link">
<a href="#myPopup" data-rel="popup" class="ui-btn ui-btn-inline ui-corner-all">Show Popup</a>
<div data-role="popup" id="myPopup">
<button id="showPopUpButton">Click me</button>
<p>This is a simple popup.</p>
</div>
</div>
<span>|</span>
</li>
&#13;
答案 1 :(得分:0)
Jquery Code有效:
$("#myPopup").ready(function() {
var popUpList = $(
'<div><input type="radio" name="popup_w" value="1">1<br><input type="radio" name="popup_w" value="2">2<br><input type="radio" name="popup_w" value="3">3</div>'
);
$('#showPopUpButton').on('click',function() {
popUpList.dialog();
});
});
JSP CODE:
<li class="header_navigation_list">
<div data-role="main" class="header_navigation_link">
<a href="#myPopup" data-rel="popup" class="ui-btn ui-btn-inline ui-corner-all">Show Popup</a>
<div data-role="popup" id="myPopup">
<button id="showPopUpButton"> To change the window size, click here</button>
<!-- <p>This is a simple popup.</p> -->
</div>
</div>
<span>|</span>
</li>