我e.preventDefault();用来禁用默认锚行为.
有没有办法阻止只在点击时跳转到目标?
我试过了:
var hash = window.location.hash;
var link = $('a');
$('a').click(function() {
e.preventDefault();
hash = "#"+link.attr("href");
});
Run Code Online (Sandbox Code Playgroud)
但它不起作用:http://jsfiddle.net/ynts/LgcmB/.
为什么看起来类似的代码片段以不同的方式工作?
<input data-value-max="10">
Run Code Online (Sandbox Code Playgroud)
1.如果脚本option来自attr,它总是input以option值更新:
$('input').keyup(function(e) {
var $this = $(this);
option = $this.attr('data-value-max');
val = $this.val();
if (val > option){ // ?---
e.preventDefault();
$this.val(option);
}
});
Run Code Online (Sandbox Code Playgroud)
我的意思是,如果我输入3或10脚本更新输入10.
2.第二种变体的工作方式与我预期的一样 - 只有当输入值大于if语句中的数字时才替换输入值:
$('input').keyup(function(e) {
var $this = $(this);
option = $this.attr('data-value-max');
val = $this.val();
if (val > 10){ // ?---
e.preventDefault();
$this.val(option);
}
});
Run Code Online (Sandbox Code Playgroud)
所以我无法理解为什么第一个变体会一直替换输入值?
我想从文件中获取宽度以将其用作变量.试着这样:
iconOS_img = new Image();
iconOS_img.src = '/details/images/icon.png';
var iconOS_img_width = iconOS_img.width;
alert(iconOS_img_width);
Run Code Online (Sandbox Code Playgroud)
然而,它返回0.
此函数返回url : <?php get_theme_url(); ?>. 我怎样才能将它用作变量?
我试过这段代码,但它不起作用:
<?php
$a = get_theme_url();
$files = glob( '$a/tariffs/tariff-b*.php' );
foreach( $files as $file ) {
include( $file );
echo $tariff_about;
?>
Run Code Online (Sandbox Code Playgroud)
更新:
谢谢!我会用双引号.
但是,现在这两个<?php get_theme_url(); ?>和
<?php
$a = get_theme_url();
$files = glob( $a."/tariffs/tariff-b*.php" );
foreach( $files as $file ) { include( $file );
echo $tariff_about; }
?>
Run Code Online (Sandbox Code Playgroud)
只返回http://localhost/.
它能是什么?
使用HeadJS加载的脚本仅在第二次单击时运行.如何在第一次点击时获得Aviary发射器?
http://jsfiddle.net/ynts/6hgEb/
function aviary(id, src) {
var $id = id;
var $src = src;
head.load(
"http://feather.aviary.com/js/feather.js",
function() {
var featherEditor = new Aviary.Feather({
apiKey: 12345,
apiVersion: 3
// ... ///
});
featherEditor.launch({
image: $id,
url: $src
});
}
);
}
$(document).on('click', 'img', function(){
var $img = $(this).attr('src');
aviary('edit-pic', $img);
});
Run Code Online (Sandbox Code Playgroud) 我想替换这段代码:
$html=<<<EOF
<p>{${$var[i]}[name]}</p>
<p>{${$var[i+1]}[name]}</p>
<p>{${$var[i+2]}[name]}</p>
<p>{${$var[i+3]}[name]}</p>
EOF;
Run Code Online (Sandbox Code Playgroud)
用这样的东西:
$html=<<<EOF
<p>{${$var[new_i]}[name]}</p>
<p>{${$var[new_i]}[name]}</p>
<p>{${$var[new_i]}[name]}</p>
<p>{${$var[new_i]}[name]}</p>
EOF;
Run Code Online (Sandbox Code Playgroud)
并保留第一段代码的功能.
有可能吗?