小编A. *_* Z.的帖子

如何防止锚点击跳转?

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/.

anchor jquery

12
推荐指数
3
解决办法
4万
查看次数

jQuery中的variable和if语句问题

为什么看起来类似的代码片段以不同的方式工作?

<input data-value-max="10">
Run Code Online (Sandbox Code Playgroud)

1.如果脚本option来自attr,它总是inputoption值更新:

$('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)

我的意思是,如果我输入310脚本更新输入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)

所以我无法理解为什么第一个变体会一直替换输入值?

jquery

2
推荐指数
1
解决办法
91
查看次数

如何使用jQuery从文件中获取图像大小?

我想从文件中获取宽度以将其用作变量.试着这样:

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.

jquery

1
推荐指数
1
解决办法
99
查看次数

PHP.如何使用函数结果作为变量?

此函数返回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/.

它能是什么?

php variables function

0
推荐指数
2
解决办法
219
查看次数

使用HeadJS加载的脚本仅在第二次单击时运行

使用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)

javascript aviary

0
推荐指数
1
解决办法
252
查看次数

PHP变量,每次出现都得+ 1

我想替换这段代码:

$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)

并保留第一段代码的功能.

有可能吗?

php variables

-2
推荐指数
1
解决办法
145
查看次数

标签 统计

jquery ×3

php ×2

variables ×2

anchor ×1

aviary ×1

function ×1

javascript ×1