从段落标签获取值

Get value from paragraph tag

本文关键字:获取 标签 段落      更新时间:2023-09-26

我需要从段落标签中获取值

<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",而不是变量的值。要做到这一点,您需要单独添加属性。更多信息在这里。

<<p> 固定代码/strong>
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>

相关文章: