小编Ror*_*san的帖子

创建一个在敌人死亡后结束的循环

我如何使用Javascript OOP制作一个循环直到玩家击败敌人?

var character = {};
character.health = 5;
character.damage = 1;

var npc = {};
npc.health = 5;

do {
    npc.health = npc.health -= character.damage;
    document.write(npc.health + "<br>");
}

while (npc.health != 0);
    if (npc.health == 0) {
        document.write("Player wins.");
    }
Run Code Online (Sandbox Code Playgroud)

当角色伤害设置为1时可以正常工作,但一旦它超过1,它就会永远循环并且浏览器会崩溃吗?我糊涂了.另外我如何让它显示0而不是像-1等负数?

html javascript jquery

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

如何使用jquery在弹出窗口中打开pdf文件

我的代码抛出JS错误,offsetParent未设置 - 无法滚动.我试过position: relative;但它仍然显示相同的错误.

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script src="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.9/jquery-ui.js" type="text/javascript"></script>
<link href="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.9/themes/blitzer/jquery-ui.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
    $(document).ready(function() {
        $('#btnShow').click(function(){
            $("#dialog").dialog();
        }); 
    });                  
</script>

<a href="#" id="trigger">this link</a>
<div id="dialog" style="display: none; position: relative; height: 4em; overflow: scroll;">
    <div>
        <iframe src="reports/my_pdf.pdf"></iframe>
    </div>
</div>
Run Code Online (Sandbox Code Playgroud)

html javascript jquery

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

如何获取具有动态创建的id的元素的值

这是我的代码:

$(".cbtn").click(function(e) {
    alert("here");
    var id = $(this).attr('id');
    var comment = $('input[id$=id]').val();     
    alert("hay" + id);
    alert(comment);

    $.post("comments.php", {
        id: id, 
        comment: comment
    })
});
});
Run Code Online (Sandbox Code Playgroud)

idof cbtn和文本字段是动态创建的,如下所示:

<input type="text" class="enter_comment  value="comments" id="comm<?php echo $row['p_id'];?>"/>
<input type="button" value="enter" class="cbtn" id="<?php echo $row['p_id'];>">
Run Code Online (Sandbox Code Playgroud)

cbtn被点击时,我想要得到的id文本字段具有相同ID的目的cbtn。但是它正在返回undefined

html php jquery

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

如何获取div中的所有元素

我只能得到input标签,但我也希望得到textarea标签.我怎样才能做到这一点?

<div class="common-div">
    <input type="text" name="confirm-pwd"/>
    <textarea cols="150" rows="5"></textarea>
</div>

<script>
    $(".common-div input").each(function() {}):
</script>
Run Code Online (Sandbox Code Playgroud)

javascript jquery

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

在Javascript中删除子数组项

如何从id = 2JavaScript/jQuery中的以下数组中删除整个子数组项?

arr = [{
    "id": 1,
    "name": "Steve"
},{
    "id": 2,
    "name": "Martin"
},{
    "id": 3,
    "name": "Short"
}]
Run Code Online (Sandbox Code Playgroud)

我不确定如何使用grepsplice在这种情况下.

我想要的输出是:

newArr = [{
    "id": 1,
    "name": "Steve"
},{
    "id": 3,
    "name": "Short"
}]
Run Code Online (Sandbox Code Playgroud)

javascript arrays jquery

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

如何定位具有相同ID的div

我目前有一些ASP.Net代码,它构建一个输出,然后通过字符串文字显示它.我们的想法是,每个人Receipt都有一个"查看更多"按钮,可以切换display: none;要开始的额外信息.我试图用这个eq()方法试图找到我想要切换的那个,因为我在里面做了ul.我目前的代码是这样的:

$("#btn-expand").click(function () {
    var ldx = $("#list li .active").index(); // Get the list number so we know what ID to work with
    var idx = $("#expand").next().index(); // Get the next ID index point

    // Check that it isn't going negative
    if (idx == -1 || ldx == -1) {
        // If it is, reset ldx
        ldx = 0;
        idx = 0;
    }

    $("#expand").eq(ldx).toggle(); // Toggle that one
    console.log(ldx);
});
Run Code Online (Sandbox Code Playgroud)

第一个按钮工作正常,然后 …

javascript jquery

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

单击&lt;td&gt;时获取父&lt;tr&gt;的值

我有以下表结构:

<tr class="tabrow" val="12345"> 
    <td class="clickable">abcde</td> 
    <td class="clickable">fghij</td> 
    <td class="clickable">2016-03-03 15:35:45</td> 
</tr>
Run Code Online (Sandbox Code Playgroud)

val当我单击任何字段时,我想要一种获取行的方法。到目前为止,我已经知道了:

$('.clickable').on('click', function() {
    evID = $(this).closest('tr').val();
    alert(evID);
})
Run Code Online (Sandbox Code Playgroud)

这行不通;它只是返回一个空白结果。我也试过了,这也行不通:

evID = $(this).parent().val();
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?

jquery

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

委托事件处理程序不起作用

这是我的HTML文件的一部分;

<script type="text/template" id="_profile">
    <div class="modalDialog">
        <div class="profile">
            <div class="box clearfix">
                <div class="box-header clearfix">
                    <span class="box-title l">{% trans 'PROFILE' %}</span>
                    <a href="#" style="margin-left: 10px;" id="profile_export" class="l"><span class="icon-download"></span>{% trans 'Profile Export' %}</a>
                    <div class="close-profile icon-cancel-circled r"></div>
                </div>
Run Code Online (Sandbox Code Playgroud)

$('.profile').on('click', '#profile_export', function (e) {
    e.preventDefault();
    $.get(root + '/profile/export/', function(resp) {
         // DO something
Run Code Online (Sandbox Code Playgroud)

我已经看了一些"jQuery中的事件委托"的例子,所以我写了上面的函数.可能是错的,因为当我点击它时,它什么也没做.它只是放在#当前URL的末尾.

谁能告诉我这里有什么问题?为什么当我点击#profile_export它不会触发"profile/export /"的请求?

谢谢

javascript jquery

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

on()不识别一个类

我正面临着一个问题on().这是我的代码:

<span class="add" id="id_foo" >add this stuff</span>
Run Code Online (Sandbox Code Playgroud)
$(".add").on('click', function() {
    $.post("/toto.com/add.php", { trainning: this.id }, function() {});
    $(this).html("Remove this stuff");
    $(this).removeClass("add").addClass("remove");
    //alert($(this).attr("class"));-->give the good class
});

$(".remove").on('click', function() {
    //doesn't work
    $.post("/toto.com/remove.php", { trainning: this.id }, function() {});
    $(this).html("add this stuff");
    $(this).removeClass("remove").addClass("add");
});
Run Code Online (Sandbox Code Playgroud)

类的选择器remove无法识别它,而当我单击带有add类的按钮时,类正在改变.你知道问题是什么吗?

谢谢您的帮助!

html javascript jquery

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

使用 jquery 更改输入的 id

您好,我在表中有一个带有值的 td,当单击按钮时,我已将此 td 更改为文本类型的输入。

现在我想用 td 元素的 id 更改新输入的 id,所以我有一个例外:

input.id 不是函数

这是我的代码js:

$("tr.forc td.TdbeforeForcage").each(function () {
    var html = $(this).html();
    var input = $('<input class="numberforce" style="width:50%" type="text" />');
    var IdTd = $(this).attr("id");
    input.val(html);
    input.id(IdTd); // Here trying to change id of input with id of td 
    $(this).html(input);

    if (html.indexOf('&nbsp;') > -1) {
      var newValue = html.replace('&nbsp;', ' ');
      $(this).find('input.numberforce').val(newValue)
    }
});
Run Code Online (Sandbox Code Playgroud)

html javascript jquery

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

标签 统计

jquery ×10

javascript ×8

html ×5

arrays ×1

php ×1