English 中文(简体)
以<a>部分为基础,在<a>后加入<li>
原标题:Adding a ID to a <li> based on part of an <a> tag
  • 时间:2010-04-26 18:34:53
  •  标签:
  • jquery

我有以下法典:

<li class="zoneName"><a href="/Default.aspx?PageID=4869007">CYKF</a></li>
<li class="zoneName"><a href="/Default.aspx?PageID=4868459">YKA</a></li>

我需要为名单上的每个区、区、区和区添加和编号。 我需要将国际发展法作为护法末尾的数字。 下面是我喜欢的。

<li class="zoneName" id="4869007"><a href="/Default.aspx?PageID=4869007">CYKF</a></li>
<li class="zoneName" id="4868459"><a href="/Default.aspx?PageID=4868459">YKA</a></li>

感谢任何帮助。

最佳回答
$("li>a").each(function(i,el){

    var id = $(this).attr("href").split("=")[1];
    $(this).parent().attr("id", id);

})
问题回答

在服务器-侧端口中书写的“电离层”吗? 请更正在<代码><li>标签上?

如果它必须是 j子,你会到这里去。

$("li a").each( function() {
  var match = /PageId=(d+)$/.exec(this.href);
  if (match) $(this).parent("li")[0].id = match[1];
});

如果<代码>href 始终只在查询的<代码>PageID部分和上出现分类账。 ∗∗∗∗∗∗∗∗∗∗∗

$( li ).each( function() {
    var href_val = $(this).children( a ).attr( href );
    var regex =  [0-9]+ ;
    var new_id = new RegExp(regex, href_val);

    $(this).attr( id , new_id);
});

这只是从头开始。 Go reg more





相关问题
getGridParam is not a function

The HTML: <a href="javascript:void(0)" id="m1">Get Selected id s</a> The Function: jQuery("#m1").click( function() { var s; s = jQuery("#list4").getGridParam( selarrrow )...

selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

jQuery cycle page with links

I am using the cycle plugin with pager functionality like this : $j( #homebox ) .cycle({ fx: fade , speed: fast , timeout: 9000, pager: #home-thumbs , ...

jquery ui dialog opens only once

I have a button that opens a dialog when clicked. The dialog displays a div that was hidden After I close the dialog by clicking the X icon, the dialog can t be opened again.

jConfirm with this existing code

I need help to use jConfirm with this existing code (php & Jquery & jAlert). function logout() { if (confirm("Do you really want to logout?")) window.location.href = "logout.php"; } ...

Wrap text after particular symbol with jQuery

What I m trying to do, is wrap text into div inside ll tag. It wouldn t be a problem, but I need to wrap text that appears particularly after "-" (minus) including "minus" itself. This is my html: &...