1

要素を 1 行または 2 行に結合して、この jquery コードを記述するためのより良い方法はありますか?

jQuery('#pinfo').attr('href', 'mailto:roaming@domain.com'  );
jQuery('#pinfo').attr('class','pullup');
jQuery('#prelated').attr('href', 'mailto:roaming@domain.com'  );
jQuery('#prelated').attr('class','pullup');
4

3 に答える 3

4

キーと値のペアをオブジェクトとして提供することで、複数の属性を設定できます。JQuery では、複数のターゲットに属性を設定することもできます - を使用してそれらを選択するだけ$("selector1, selector2")です。

jQuery('#pinfo, #prelated').attr({ 
    href: "mailto:roaming@domain.com", 
    class: "pullup" 
});
于 2013-10-07T23:34:24.203 に答える