我真的很好奇谷歌(现在Facebook在照片库中)如何实现快捷键,如J/ K或←/ →箭头.我担心我没有太多的细节,因为我无法通过检查来源确定那些按钮"tic",可以这么说.我特别想要的是一种将按钮绑定到Javascript函数的方法 - 从那里,它显然相当容易.
好吧,标题可能没有任何意义..但无论如何,我可以用一些简单的代码来澄清它.
我正在使用JQuery 1.3.2
这是我的JS
$(document).ready(function() {
$('#test').click(function() {
$('#result').html('<a href="#" id="hello">hello world</a>');
});
$('#hello').click(function() {
$('#result').html('<a href="#" id="asdf">Test #2</a>');
});
});
Run Code Online (Sandbox Code Playgroud)
在html中,我有一个超链接id ='test'和一个id ='result'的div.我期望这个JS代码是当我点击测试时,它显示"Hello World".之后,当我点击"Hello World"时,它应该显示"Test#2"
任何建议都非常有帮助......
谢谢.
我如何处理jQuery,以便只有在按下鼠标左键的情况下才能激活mousemove事件,并且只要按钮被释放,mousemove事件就会停止?
假设我有一个链接列表:
<a id="home" href="#"> home link </a><br/>
<a id="list1" href="#"> some text1 </a><br/>
<a id="list2" href="#"> some text2 </a><br/>
<a id="list3"> href="#"> some text3 </a><br/>
<a id="list4" href="#"> some text4 </a><br/
<a id="list5" href="#"> some text5 </a><br/>
<a id="list sails" href="#"> sails link </a><br/>
Run Code Online (Sandbox Code Playgroud)
如果单击某个列表链接,我会收到包含其文本的警报
我写了一个脚本,但它不对,它看起来像这样
function lunch(){
alert( $(this).text()) }
Run Code Online (Sandbox Code Playgroud)
对于
<a id="listn" href="#" onclick="lunch()"> some text5 </a><br/>
Run Code Online (Sandbox Code Playgroud)
如何在jquery或javascript上执行此操作?
如何-用\javascript中的斜杠()替换hypen()?
例如,我需要更换
C-我的文档,VisualStudio2008-的MyProjects
同
c ^ \我的文档\ VisualStudio2008\MyProjects下
我尝试替换功能,variable.replace("-","\")但它显示我未终止字符串常量的错误
我在VS 2008工作
谢谢
.net javascript asp.net javascript-events visual-studio-2008
我正在编写一个WWW应用程序,它必须在IE下运行.我有在FF下运行的代码的问题,但我不能让它在IE下运行.
// JS代码
function test()
{
if (window.event.keyCode == 13)
window.location.assign("myPage.php");
}
Run Code Online (Sandbox Code Playgroud)
我在window.location和location.href周围尝试了一些类似的方法,也是document.location.我已经读过IE有问题,所以我要求一个解决方案.
目标是,在输入一些文本后重新加载该页面<input type='text' name='item_code' onKeyDown='test()'>,然后单击Enter.因此结果类似于在文本输入下方按提交类型按钮.
在IE中,它重新加载相同的页面,没有任何反应.在FF它正确工作.
更新1:
由bobince给出的尝试解决方案.
<input type='text' name='item_code'>
<script type='text/javascript' >
document.getElementsByName('item_code')[0].onkeydown = function(event)
{
if (event == undefined) { event = window.event; }
if (event.keyCode == 13) { window.location = 'myPage.php'; }
alert('1');
}
</script>";
Run Code Online (Sandbox Code Playgroud)
问题是,如果有alert('1');行,页面显示警报和重定向,如果没有alert('1');行,页面只是重新加载到自身.我不知道这里有什么问题?
更新2:
我正在粘贴最终适合我的东西.
<form action='mainPage.php' method='POST'>
<input type='text' name='item_code'>
</form>
<script type='text/javascript' >
document.getElementsByName('item_code')[0].onkeydown= function(event)
{
if (event == undefined)
{
event = …Run Code Online (Sandbox Code Playgroud) 我正在使用tablesorter和tablesorter.pager.这是我的代码.
$(document).ready(function() {
$("#peopletable")
.tablesorter({ widthFixed: true, widgets: ['zebra'] })
.tablesorterFilter({ filterContainer: $("#people-filter-box"),
filterClearContainer: $("#people-filter-clear-button"),
filterColumns: [1, 2, 3],
filterCaseSensitive: false
})
.tablesorterPager({ container: $("#peoplepager") });
$("#peopletable tr.data").click(function() {
var personid = $(this).attr('id');
$.ajax({
type: "POST",
url: "/Search/GetDocumentsByPerson",
data: { "id": personid },
datatype: "json",
success: function(data) {
var results = eval(data);
$("#documentstable > tbody tr").remove();
$.each(results, function(key, item) {
$("#documentstable > tbody:last").append(html);
});
$("#documentstable").trigger("update");
}
});
});
});
Run Code Online (Sandbox Code Playgroud)
一切都很好,除非我点击下一页我的按钮点击事件不会触发.这是jquery tablesorter的已知问题吗?
当其他javascript函数更改已检查状态时,我需要触发更改事件.以下简化代码.我不能从MyOtherFunc()调用MyFunc().
jQuery的:
$(document).ready(function(){
$('input:radio[name=rdName]').change(function(){
MyFunc();
});
});
function MyFunc(){
//do stuff
}
function MyOtherFunc(){
$('input:radio[name=rdName]')[0].checked = true;
// Was unable to have it change based on a value
}
Run Code Online (Sandbox Code Playgroud)
单选按钮:
<input type="radio" name="rdName" value="1">
<input type="radio" name="rdName" value="2">
<input type="radio" name="rdName" value="3">
Run Code Online (Sandbox Code Playgroud) 我有一个网页,我在流行音乐中显示结算信息.此弹出窗口是DIV而不是新窗口.在那个弹出窗口中,有两个div用于保持打印和关闭按钮,另一个用于保存iframe.
然后原因是当点击打印按钮时,打印iframe的内容,以便不打印打印和关闭按钮.它像是...
<div id='popupandcenterscreen'>
<div>... print and close buttons</div>
<div><iframe></div>
</div>
Run Code Online (Sandbox Code Playgroud)
因此,它是一个列表,其中每个条目都有一个账单链接,当点击弹出窗口时,其中加载iframe以显示账单信息.
当用户单击打印按钮时,我们仅打印iframe的文档内容.
但是,当用户使用CTRL + P时,包括背景资格父窗口在内的总窗口将打印出来.
我认为在弹出窗口打开时捕获ctrl + p并仅打印iframe内容.
怎么可能呢?
我以这种方式使用事件委托:
elWraper.onclick = (function(){
//how to get here "event" object
e = e || window.event;
var t = e.target || e.srcElement;
//event handler
return function(){
//manipulations with "t" variable
}
})();
Run Code Online (Sandbox Code Playgroud)
如何在立即执行的函数中获取"事件"对象?