我当前的代码只传递一个参数值。但我想用两个参数传递两个值。
我当前的代码
<script>
function getfilter(str){
document.getElementById("result").innerHTML="<div class='sparea'><i class='fa fa-spinner fa-spin sparea' ></i><div></script";
if (str==""){
document.getElementById("result").innerHTML="";
return;
}
$.ajax({
url: "Views/mapresult.php?q="+str,
type: "GET",
success: function ( responseText ) {
$("#result").empty().append($(responseText));
}
});
}
</script>
<li class="android" data-mosaic-filterby="android" onclick="getfilter(this.id)" id="'.$cd[$i][0].'" >'.$cd[$i][1].'</li>
但我想传递两个参数
喜欢
<li class="android" data-mosaic-filterby="android" onclick="getfilter(this.id)" id1="'.$cd[$i][0].'" id2="'.$cd[$i][0].'" >'.$cd[$i][1].'</li
答案 0 :(得分:0)
$(function() {
$(".android").on("click",function(e) {
var id1 = $(this).data("id1");
var id2 = $(this).data("id2");
if (id1!="") {
$("#result").html("<div class='sparea'><i class='fa fa-spinner fa-spin sparea' ></i><div>");
$.ajax({
url: "Views/mapresult.php?q="+id1+id2,
type: "GET",
// data: serializedData,
success: function ( responseText ) {
$("#result").empty().append($(responseText));
}
});
}
});
</script>
<li class="android" data-mosaic-filterby="android" data-id1="'.$cd[$i][0].'" data-id2="'.$cd[$i][0].'" >'.$cd[$i][1].'</li
答案 1 :(得分:0)
你不需要onclick的东西。您可以将数据直接存储在列表项的属性中。
<li class="android" data-mosaic-filterby="android" data-first="Some data" data-second="some other data">Click Me</li>
这个javascript。
$(document).ready(function(){
// listen for clicks on that element
$('.android').on('click', function(){
// get the data
var data1 = $(this).attr('data-first'),
data2 = $(this).attr('data-second');
// Send the data to your function.
// There are 10 other ways to do this but this'll work.
getfilter(data1, data2);
});
});
function getfilter(data1, data2){
var spinner = "<div class='sparea'><i class='fa fa-spinner fa-spin sparea' ></i><div>",
$result = $('#result');
// if you're gonna drink the kool-aid, drink it!
$result.html(spinner);
// double check however you like.
if (data1==""){
$result.html("");
return;
}
$.ajax({
url: "Views/mapresult.php?q=",
type: "GET",
// Format your data into an object
// jQuery will take care of the rest
data: {
"data1" : data1,
"data2" : data2
},
success: function ( responseText ) {
$("#result").html(responseText);
}
});
}
这是一个小提琴。 http://jsfiddle.net/4kC8b/