당신은 iterate over a group of divs or lis or whatever with JQuery을 수에 대한
<?php foreach($main_tags as $key=>$value){ ?>
<li>
<a id="<?php echo $key; ?>" href="#" onclick="tag_search('<?php echo $key; ?>'); return false;">
<?php echo $key; ?>
<span class="num-active">
<?php echo $value; ?>
</span>
</a>
</li>
<?php } ?>
모두 감사합니다.
아래 코드는 PHP를 표시하지 않으며 JQery의 상황을 알려주는 경고를 사용합니다 ... 실제 코드가 될 것이라고 의견을 말했습니다 .... 도움이 되길 바랍니다. 이와 같이 항목의 순서가 중요하기 때문에 ID에 대해 걱정할 필요가 없습니다. 물론 당신의 ID를 떠날 수
편집 - 처리 사용자 정의 키
사례 1 방법을 추가 :. 숫자 키
<!DOCTYPE html>
<html lang="en">
<head>
<title>Binding events</title>
<script type="text/javascript" src="JQUERY-PATH/jquery-1.4.2.min.js"></script>
<meta charset="utf-8" />
<script type="text/javascript">
// When the page is ready ==================================================
$(document).ready(function()
{
$('li').each(function(index)
{
// The line below would read something like:
// $(this).click(function() {tag_search(index)});
$(this).click(function() { alert("This would trigger => tag_search(" + index + ")")});
});
});
</script>
</head>
<body>
The php goes into the unordered list:
<ul>
<li>zero</li>
<li>one</li>
<li>two</li>
<li>three</li>
<li>four</li>
<li>five</li>
</ul>
</body>
</html>
사례 2 : 당신의 선택의 사용자 정의 키
숫자가 모두있는 키가있는 경우 임의의 문자를 앞에 붙여서 ID 또는 클래스 이름의 유효성을 검사 할 수 있습니다.
<!DOCTYPE html>
<html lang="en">
<head>
<title>Binding events</title>
<script type="text/javascript" src="jquery-1.4.2.min.js"></script>
<meta charset="utf-8" />
<script type="text/javascript">
// When the page is ready ==================================================
$(document).ready(function()
{
$('li').each(function(index)
{
// The line below would read something like:
// $(this).click(function() {tag_search($(this).attr('id'))});
$(this).click(function() { alert("This would trigger => tag_search(" + $(this).attr('id') + ")")});
});
});
</script>
</head>
<body>
The php goes into the unordered list:
The custom keys are placed in ids or classes:
<ul>
<li id="Roger">zero</li>
<li id="Dodger">one</li>
<li id="23884">two</li>
<li id="Fubar">three</li>
<li id="Gungho">four</li>
<li id="Burlap">five</li>
</ul>
</body>
</html>
JavaScript가 꺼져있을 때 폴백 솔루션을 제공해야한다고 생각합니다. 'href = "#"'는 아무 것도 이끌지 않습니다. –
@Marcel - JS가없는 사용자가 내 사이트를 방문하는 것을 원하지 않습니다. 약간 잔인하지만이 앱의 성격 때문에 그렇게해야합니다. – Abs