1

一連の動的に生成されたラジオ ボタンを持つページにグリッドがあります。すべてのラジオ ボタンには類似した ID 名が付いていますが、ID 名の中央にある増分変数 CTL## (ctl00、ctl01 など) を除きます。

<input id="ctl00_PageBody_grdCustomer_ctl01_rdoCustomerSelect" type="radio" value="rdoCustomerSelect">
<input id="ctl00_PageBody_grdCustomer_ctl02_rdoCustomerSelect" type="radio" value="rdoCustomerSelect">
<input id="ctl00_PageBody_grdCustomer_ctl03_rdoCustomerSelect" type="radio" value="rdoCustomerSelect">
<input id="ctl00_PageBody_grdCustomer_ctl04_rdoCustomerSelect" type="radio" value="rdoCustomerSelect">
<input id="ctl00_PageBody_grdCustomer_ctl05_rdoCustomerSelect" type="radio" value="rdoCustomerSelect">

特定のパターンで開始/終了する場合に ID に一致するコードを見つけましたが、一致するパターンを抽出して属性に割り当てる方法がわかりません。

私の最終目標は、タグを次のようにフォーマットすることです...

<input id="ctl00_PageBody_grdCustomer_ctl01_rdoCustomerSelect" type="radio" value="rdoCustomerSelect" title="rdo_ctl01">
<input id="ctl00_PageBody_grdCustomer_ctl02_rdoCustomerSelect" type="radio" value="rdoCustomerSelect" title="rdo_ctl02">
<input id="ctl00_PageBody_grdCustomer_ctl03_rdoCustomerSelect" type="radio" value="rdoCustomerSelect" title="rdo_ctl03">

等々...

助言がありますか?ありがとう。

4

2 に答える 2

1

試す:

$('input').attr('title', function () {
    var matches = $(this).attr('id').match(/ctl00_PageBody_grdCustomer_(.*)_rdoApplicantSelect/);
    return 'rdo_' + matches[1];
});

jsFiddle の例

これにより、次が生成されます。

<input id="ctl00_PageBody_grdCustomer_ctl01_rdoApplicantSelect" type="radio" value="rdoApplicantSelect" title="rdo_ctl01">
<input id="ctl00_PageBody_grdCustomer_ctl02_rdoApplicantSelect" type="radio" value="rdoApplicantSelect" title="rdo_ctl02">
<input id="ctl00_PageBody_grdCustomer_ctl03_rdoApplicantSelect" type="radio" value="rdoApplicantSelect" title="rdo_ctl03">
<input id="ctl00_PageBody_grdCustomer_ctl04_rdoApplicantSelect" type="radio" value="rdoApplicantSelect" title="rdo_ctl04">
<input id="ctl00_PageBody_grdCustomer_ctl05_rdoApplicantSelect" type="radio" value="rdoApplicantSelect" title="rdo_ctl05">
于 2013-10-16T14:53:28.303 に答える
0

使用できますsplit()

$('input').attr('title', function() {
    return 'rdo_' + this.id.split('_')[3]; 
});

ここにフィドルがあります

于 2013-10-16T14:57:34.067 に答える