0

関数に変換されたときに同じアクションが機能しなくなるのはなぜですか?一般的なルールはありますか?これは、この問題の非常に具体的で明確な例です。

jQuery Mobile、http://jsbin.com/osovoh/2/edit

このバージョンでは、jsがうまく機能します。ラジオボタンのラベルは即座に変更されます。

var radio_elem = $('#edit-new-amount-no-cost');
$("label[for='edit-new-amount-no-cost']").html(radio_elem).append("label changed");

ただし、/ *を削除して、同じアクションを他のボタンによってトリガーされる関数に変換すると、

function go() {
    var radio_elem = $('#edit-new-amount-no-cost');
    $("label[for='edit-new-amount-no-cost']").html(radio_elem).append("label changed");
}

同じコードが宛先のフォーマットを台無しにします。どうしたの?

4

2 に答える 2

0

ここに答えがあります:

 <!DOCTYPE html>
<html>
<head>
  <meta name="description" content="WORKING: replace text in radiobutton" />
<meta charset=utf-8 />
<title></title>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.css" />
<script src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
<script src="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js"></script>
</head>

<body style="text-align:center">
<div class="form-radios">
  <div class="form-item" id="edit-new-amount-no-cost-wrapper">
    <label class="option" for="edit-new-amount-no-cost" >
    <input type="radio" id="edit-new-amount-no-cost" name="new_amount" value="no_cost" class="form-radio"/>
    original label
    </label>
  </div>
    </div>
<input name="click to change the label" type="button" onClick="go()">
<script> 

function go(){



$("label[for='edit-new-amount-no-cost'] .ui-btn-text").html("label changed");


}

 </script>



  </body>

</html>
于 2013-02-15T23:47:57.407 に答える
0

関数内にある場合、マークアップの変更は、jQuery Mobile がページをレンダリングした後に発生します。変更しているページまたは要素を jQuery Mobile に再レンダリングさせる必要があります。

于 2013-02-15T19:23:24.927 に答える