我正在尝试将onClick事件添加到锚标记...
以前我有......
<a href="somlink.html" onClick="pageTracker._link(this.href); return false;">
但我试图避免内联onClick事件,因为它干扰了另一个脚本..
所以使用jQuery我正在尝试以下代码...
<script>
$(document).ready(function() {
$('a#tracked').attr('onClick').click(function() {window.onbeforeunload = null;
pageTracker._link(this.href);
return false;
});
});
</script>
Run Code Online (Sandbox Code Playgroud)
跟html一样 <a id="tracked" href="something.html">
所以我的问题是这应该是有效的,如果不是最好的解决方案是什么?
可以说我有多个像这样的cookie:
add_listing_123=1
add_listing_456=1
add_listing_789=1
Run Code Online (Sandbox Code Playgroud)
如何检索以"add_listing_"开头的所有cookie?
当检索到我如何使用php解析cookie中的数字时,我的最终结果是123,456,789的数组?
我试图基于字符串(整数)的值创建一个数组,例如:
// my string
$dogs = '2';
// my array
$dogs_array = array(
[0] => 'Dog 1',
[1] => 'Dog 2'
);
Run Code Online (Sandbox Code Playgroud)
因此,如果字符串为4,则数组中将有4个项目.这可能吗?如果是这样,怎么办呢?
提前致谢.
看起来像一个非常基本的问题,但我怎样才能简化数组,例如:
Array
(
[0] => Array
(
[blue_dog_1] => 2
)
[1] => Array
(
[red_dog_1] => 4
)
[2] => Array
(
[red_dog_2] => 6
)
)
Run Code Online (Sandbox Code Playgroud)
像是:
Array
(
[blue_dog_1] => 2
[red_dog_1] => 4
[red_dog_2] => 6
)
Run Code Online (Sandbox Code Playgroud)
提前致谢.
我试图设置一个延迟时间的cookie.
我希望在页面上80分钟后设置cookie.
这是我的代码 -
$(document).ready(function() {
// Set the cookie after 81 mins so the next visit has the button
$.cookie('EVGSalesLetter', 'visited').delay(4860000);
});
Run Code Online (Sandbox Code Playgroud) 如何使用js获取URL哈希的一部分?
这是我所拥有的:
something.html?il=#/new/product/123
我需要将“123”作为变量......
***没有库,请使用纯 JavaScript。
有任何想法吗?