English 中文(简体)
Jquery and Drop Down - 确定价值
原标题:Jquery and Drop Down - Determine the Values
  • 时间:2012-05-10 19:11:25
  •  标签:
  • jquery
  • html

我的下降是,我需要将下降幅度内的数值(“平衡<>>/em>)进行比较,并将之与全球变量进行比较,然后做一个显示某种超文本的表述。

下降:

 <select name="batch">
 <option value= null >-- None --</option>
 <option value= 96 >Check (#2200) (Bal. $84.00) - Jim Jones</option>
 <option value= 98 >Credit Card (#0) (Bal. $90.00) - Bailey Adams</option>
 </select>

这里是我的 j:

    $("select[name=batch]").change(function () {
    if ($(this).val() >= GlobalTotal) {
        $("th#show_refund").show();
        $("th#no_show_refund").hide();
    } else {
        $("th#show_refund").hide();
        $("th#no_show_refund").show();
    }
});

是否可以 j忙确定在超文本选择中有哪些平衡? 如果是的话,我很想让我走上正确方向。

最佳回答

我假定你正在积极建设这一关系。 在每一种选择中,添加一个属性<代码>数据平衡=84。 或不论平衡是什么,如果使用 j,你将使用 the。

$("select[name=batch] option:selected").attr("data-balance")

因此,你的完整法典是:

<select name="batch">
    <option value= null >-- None --</option>
    <option value= 96  data-balance="84.00">Check (#2200) (Bal. $84.00) - Jim Jones</option>
    <option value= 98  data-balance="90.00">Credit Card (#0) (Bal. $90.00) - Bailey Adams</option>
</select>

$("select[name=batch]").change(function () {
    if ($("select[name=batch] option:selected").attr("data-balance") >= GlobalTotal) {
        $("th#show_refund").show();
        $("th#no_show_refund").hide();
    } else {
        $("th#show_refund").hide();
        $("th#no_show_refund").show();
    }
});
问题回答

您可从选定价值的<代码>inner Rainbow/code>中提取这一数值:

// Store our Global Total
var gTotal = 87;
// Bind to the change event of our dropdown
$("select[name= batch ]").on("change", function(){
  // If we find a dollar amount in our selected element, save it to `amount`
  if ( amount = $(":selected", this).html().match( /$(d+.d{2})/ ) )
    // If that amount is greater than the Global Total
    amount[1] >= gTotal
      // Do something when it s greater than
      ? console.log( amount[1] +   is greater than   + gTotal )
      // Do something else when it s lesser than
      : console.log( amount[1] +   is less than   + gTotal ) ;
});

页: 1

更妥善地确定你们对余额的选择价值,例如:

<select name="batch">
    <option value= null >-- None --</option>
    <option value= 84.00 >Check (#2200) (Bal. $84.00) - Jim Jones</option>
    <option value= 90.00 >Credit Card (#0) (Bal. $90.00) - Bailey Adams</option>
</select>

这让你获得价值,而不需要任何虚幻的文本。 例如:

$("select[name=batch]").change(function () {
    if ($("select[name=batch] option:selected").val() >= GlobalTotal) {
        $("th#show_refund").show();
        $("th#no_show_refund").hide();
    } else {
        $("th#show_refund").hide();
        $("th#no_show_refund").show();
}
$("select[name=batch]").change(function () {
 var selectedText= "";
      $("select option:selected").each(function () {
            selectedText+= $(this).text() + " ";
          });




相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!