从段落标签获取值
Get value from paragraph tag
我需要从段落标签中获取值
<div id="dialog-confirm" title="<fmt:message key="label.modal.confirmation" />">
</div>
<div style="display:none" id="parent">
<p class="yes"><fmt:message key="button.modal_ok" /></p>
<p id="no"><fmt:message key="button.modal_no" /></p>
</div>
在我的javascript函数
$(function() {
var butok = $('#parent').children('p.yes').text();
$( "#dialog-confirm" ).dialog({
autoOpen: false,
resizable: false,
height:140,
modal: true,
buttons: {
butok : function() {
window.location.href = partsArray[0];
$(this).dialog( "close" );
},
butno: function() {
location.reload();
$( this ).dialog( "close" );
}
}
});
});
我怎样才能得到它?.text()和.html()不能工作
您不能像以前那样直接使用butok
,因为按钮文本将是"butok"
,而不是变量的值。要做到这一点,您需要单独添加属性。更多信息在这里。
var butok = $('#parent').children('p.yes').text(),
butno = $('#parent').children('p#no').text();
// Define an empty Object
var myButtonsObject = {};
// Add properties to it using the [ bracket ] notation
myButtonsObject[ butok ] = function() {
window.location.href = partsArray[0];
$(this).dialog("close");
};
myButtonsObject[ butno ] = function() {
location.reload();
$(this).dialog("close");
};
$("#dialog-confirm").dialog({
autoOpen: false,
resizable: false,
height: 140,
modal: true,
buttons: myButtonsObject // Use it
});
$(function() {
var butok = $('#parent').children('p.yes').text(),
butno = $('#parent').children('p#no').text();
// Define an empty Object
var myButtonsObject = {};
// Add properties to it using the [ bracket ] notation
myButtonsObject[butok] = function() {
window.location.href = partsArray[0];
$(this).dialog("close");
};
myButtonsObject[butno] = function() {
location.reload();
$(this).dialog("close");
};
$("#dialog-confirm").dialog({
autoOpen: true,
resizable: false,
height: 140,
modal: true,
buttons: myButtonsObject // Use it
});
});
<link href="http://code.jquery.com/ui/1.9.2/themes/base/jquery-ui.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script src="http://code.jquery.com/ui/1.9.2/jquery-ui.js"></script>
<div id="dialog-confirm" title="Modal title"></div>
<div style="display:none" id="parent">
<p class="yes">Yeeeees</p>
<p id="no">Nooooo</p>
</div>
相关文章:
- 无法获取标签页网址 - Chrome 扩展程序
- 火狐侧边栏获取标签网址
- Wicket:获取标签属性
- 如何使用动态生成的 id 通过 jquery 获取标签的值
- 获取标签文本并将其设置为输入值[为什么输入值只获取空格前的文本?
- 如何使用 jQuery 在标签的 for 属性中使用子字符串获取标签元素的值
- 不能从 JavaScript 中获取标签
- 如何使用javascript获取
- 需要使用 JS 获取 标签的 “id” 属性
- 从大量网址中获取标签内容
- 获取标签值并使用jquery进行算术运算
- 如何在jQueryMobile中获取标签的值并将其解析为int
- Tag-it jquery:从网络服务中获取标签
- 仍然没有添加到 DOM 中,但如果插入了警报/确认,则会获取标签 ID
- 如何获取标签值以更改我的网址
- JQuery 获取标签内的 html 字符串
- 在javascript中获取标签的rel
- 如何从stripes中获取标签值:java脚本或java中的选项集合
- 如何获取标签的文本
- jQuery正在获取标签'的内容