小编Nop*_*ope的帖子

找出哪个类触发了模糊

我使用以下函数执行验证:

//Validation
$('.sValidate').bind('blur', function() {
    if (!$(this).val()) {
        $(this).removeClass('short_input');
        $(this).addClass('short_input_negative');
        return false;
    }
});
Run Code Online (Sandbox Code Playgroud)

我的大多数输入类都是short_input.但其中一些也被命名long_input.
我怎么知道input触发了什么类blur,删除它并添加long_input_negative

<input type="text" id="loginname" name="loginname" class="short_input sValidate" value="JDoe">
Run Code Online (Sandbox Code Playgroud)

javascript jquery

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

为什么是空函数!==空函数?

var x = function() {};
var y = function() {};

alert(x === y); // is false;
Run Code Online (Sandbox Code Playgroud)

如果x初始化为相同的值,为什么x不等于y?

javascript function

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

使用jquery序列化表单不会序列化所有字段

我正在尝试使用jquery序列化我的表单,但它没有按预期工作。许多其他字段中只有一个字段被序列化。

我的HTML:

<form action="/Devis/auto" id="theForm" method="post" novalidate="novalidate"
class="ui-formwizard ui-helper-reset ui-widget ui-widget-content ui-corner-all">
    <div id="fieldWrapper">
        <fieldset id="first" class="step ui-formwizard-content" style="display: none; margin-left: -1148px; width: 1148px;">
            <legend>Information conducteur</legend>
            <div class="editor-label">
                <label for="DriverInfoViewModel_DriverInfo_NoClaimsDegree">Degré B/M</label>
            </div>
            <div class="editor-field">
                <select data-val="true" data-val-range="[fr-FR: Range]" data-val-range-max="22"
                data-val-range-min="-3" data-val-required="Le champ Degré B/M est obligatoire."
                id="DriverInfoViewModel_DriverInfo_NoClaimsDegree" name="DriverInfoViewModel.DriverInfo.NoClaimsDegree"
                class="ui-wizard-content valid" disabled="disabled">
                    <option value="-3">-3</option>
                    <option value="-2">-2</option>
                    <option value="-1">-1</option>
                    <option value="0">0</option>
                    <option selected="selected" value="1">1</option>
                    <option value="2">2</option>
                    <option value="3">3</option>
                    <option value="4">4</option>
                    <option value="5">5</option>
                    <option value="6">6</option>
                    <option value="7">7</option>
                    <option value="8">8</option>
                    <option value="9">9</option>
                    <option value="10">10</option> …
Run Code Online (Sandbox Code Playgroud)

jquery json

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

为什么我不能从2个函数内部调用该函数?

是我的代码:

inserisciMarker();

function scorriAllaLista(param) {
    alert(param);
}

function inserisciMarker() {
    markerClick = function () {
        $('#example').attr("onclick", "scorriAllaLista('hello'); return false;");
    };

    markerClick();
}
Run Code Online (Sandbox Code Playgroud)

点击链接, Uncaught ReferenceError: scorriAllaLista is not defined

为什么?我该如何解决?

javascript jquery function

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

将表单数据加载到字符串然后再加载到localStorage的最佳方法是什么?

这是将表单数据加载到字符串然后再加载的最佳方法localStorage吗?

我自己想出了这个,而且我不擅长编程.它适用于我需要的东西,但我不确定它是否是一个防弹代码?

<script>
    var sg = document.getElementById("selectedGateway");
    var sd = document.getElementById("selectedDestination");
    var dm = document.getElementById("departureMonth");
    var dd = document.getElementById("departureDay");
    var dy = document.getElementById("departureYear");
    var rm = document.getElementById("returnMonth");
    var rd = document.getElementById("returnDay");
    var ry = document.getElementById("returnYear");
    var ad = document.getElementById("adults");
    var ch = document.getElementById("option2");

    $("#searchRequestForm").submit(function() {
        var string = 'From: ' + sg.value + ' \nTo: ' + sd.value + ' \nDeparture: ' + dm.value + '/' + dd.value + '/' + dy.value + ' \nReturn: ' + rm.value …
Run Code Online (Sandbox Code Playgroud)

javascript jquery

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

为什么我会收到错误"太多的递归"?

我正在这里开展一个小项目,我得到这个消息"太多的递归",显然没有那么多.

这是相关的HTML代码

<div id="speed">
    <label for="spe">Input speed</label>
    <input type="text" id="spe" onkeydown="if (event.keyCode == 13){ javascript:CalcBySpeed(); return false; }" />
    <input type="button" name="Sumbit" value="Submit" onclick="javascript:CalcBySpeed()" />
</div>
Run Code Online (Sandbox Code Playgroud)

和一张桌子,通常看起来像这样:

<tr>
    <td id="50">
        <p id="117">5</p>
    </td>
    <td id="51">
        <p id="118">20</p>
    </td>
    <td id="52">
        <p id="119">5</p>
    </td>
    <td id="53">
        <p id="120">1,2</p>
    </td>
</tr>
Run Code Online (Sandbox Code Playgroud)

我的JavaScript函数是:

function CalcBySpeed() {
    var input = "a";
    input = parseFloat(document.getElementById("spe").value) * 100;
    if (input < 5089) {
        getValueBySpeed(input - 3);
    } else {
        alert("Value undefined!");
    }
};

function getValueBySpeed(input) { …
Run Code Online (Sandbox Code Playgroud)

html javascript recursion firefox

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

如何将变量的值添加到我的HTML?

我有2个单独的实例,我在页面的标题中显示JavaScript中的数据:

HTML:

<h2 id='Fetch_Header' style="color:white; font-family: arial;">
    The last time you fetched your games was:<span class="last_fetch" style="font-weight: bold;"></span>
</h2>
Run Code Online (Sandbox Code Playgroud)

jQuery的:

$.get('php/FetchGames/LastFetch.php', function (data) {
    if (data == "Never") {
        var lastdate = data;
        $('.last_fetch').html(" " + lastdate);
    }
Run Code Online (Sandbox Code Playgroud)

更多jQuery:

$.get('php/FetchGames/GetMatchCount.php', function (data) {
    MatchCountJson = data;
    MatchCountJson_Parsed = JSON.parse(MatchCountJson);
    MatchCount = MatchCountJson_Parsed.Int;
    //the above JSON is {"Int":72}
});

$('#Fetch_Header').html('Time to apply your MMR, follow the instructions below. Matches left to apply: ' + MatchCount);
Run Code Online (Sandbox Code Playgroud)

然而只有前者工作(最后一个).

第一输出:

日期(如预期)

第二输出:

"Time to …

html javascript jquery

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

使用数学随机生成随机不透明度数

我正在尝试为css不透明度生成一个随机数.

这是我到目前为止所尝试的.

CSS

.test{
    position : absolute;
    width : 15px;
    height : 15px;
    border-radius:15px;
    background-color : black; 
}?
Run Code Online (Sandbox Code Playgroud)

脚本

$(function() {
    for (var i = 0; i < 300; i++) {
        $("<div>", {
            class: "test",
            css: {
                opacity: randomOpacity
            }
        }).appendTo("body");
    }

    function randomOpacity() {
        var opac = 0;
        opac = Math.random() < 1;
        console.log(opac);
    }

    randomize();
});?
Run Code Online (Sandbox Code Playgroud)

小提琴

javascript random math jquery opacity

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

用外部html文件替换div与div

我有一个html文件,我想用div外部html文件中的内容\整个div 替换其中的某个内容.

我试图用jquery做这件事,但有些事情是错的.这是我到目前为止所得到的:

$("#originHtml").replaceWith(external.html #temp);
Run Code Online (Sandbox Code Playgroud)

和各种各样的组合' " '.

代码是:

$("#originDivId").replaceWith(external.html #temp);
Run Code Online (Sandbox Code Playgroud)

html jquery

-3
推荐指数
1
解决办法
2118
查看次数

为什么我检查这个数组是否进入JSON文档无法使用JavaScript?

我正在检查JSON对象是否包含特定属性.

我有这个JSON文档:

{
    "market_name": "Dakar",
    "market_description": "Tambacounda Market N1",
    "localization_id": 2,
    "long": 13.776796,
    "lat": -13.672198,
    "country": "Senegal",
    "regione": {
        "@nil": "true"
    },
    "province": {
        "@nil": "true"
    },
    "city": {
        "@nil": "true"
    },
    "district": {
        "@nil": "true"
    },
    "town": {
        "@nil": "true"
    },
    "village": {
        "@nil": "true"
    },
    "commoditiesList": {
        "commodity": [{
            "commodity_details_id": 8,
            "commodity_name_en": "Carrot",
            "commodity_name": "Carrot",
            "description": "Carrot",
            "image_link": "https://firebasestorage.googleapis.com/v0/b/fao-digital-services-portfolio.appspot.com/o/img%2Ficons%2Fagrimarket%2Fcommodity%2Fcarrot.png?alt=media&token=f295c6b3-abf8-4b51-97c9-582d9188675f",
            "market_commodity_details_id": 26,
            "price_series_id": 9,
            "last_price_date": "2017-12-18+01:00",
            "last_avg_price": 48.37,
            "currency": "XOF",
            "measure_unit": "kilogram"
        },
        {
            "commodity_details_id": 4,
            "commodity_name_en": "Red onion", …
Run Code Online (Sandbox Code Playgroud)

javascript json

-4
推荐指数
1
解决办法
67
查看次数

如何通过按键盘键来改变div?

我有两个div

<div class="summary">Summary</div>

<div class="summary-cont"><p>Content...</p></div>
Run Code Online (Sandbox Code Playgroud)

div"summary-cont"被隐藏,显示:无;

我想像这样工作:我按下键盘按钮"S"然后div"摘要"隐藏并显示div"summary-cont"

有人知道如何用javascript做到这一点?

这是工作代码:

<script>
$(document).keyup(function(e) {
  if (e.keyCode == 83) { $('.summary').hide(); }     // S
  if (e.keyCode == 83) { $('.summary-cont').show(); }   // S
});
</script>
Run Code Online (Sandbox Code Playgroud)

html javascript css keyboard jquery

-5
推荐指数
1
解决办法
983
查看次数

标签 统计

javascript ×9

jquery ×8

html ×4

function ×2

json ×2

css ×1

firefox ×1

keyboard ×1

math ×1

opacity ×1

random ×1

recursion ×1