小编Nit*_*ths的帖子

如何将div的id设置为cookie?

我有一项任务是在刷新页面时突出显示所选菜单.为此,我想使用cookie.Html代码是

<div class="menuBar">
            <div class="menuHeader ui-corner-top">
             <span><a href="#" onclick="Home()" id="home">Home</a></span>
            </div>
            <div class="menuHeader ui-corner-top">
             <span><a href="#" onclick="NewTransaction()" id="newtransaction">New Transaction</a></span>
            </div>
</div>
Run Code Online (Sandbox Code Playgroud)

Javascript文件是

function Home() {
            window.location.href = "../../home/welcome";
        }
        function NewTransaction() {
            window.location.href = "../../EnergyCatagory/index";
        }
Run Code Online (Sandbox Code Playgroud)

但我有一个代码将菜单设置为选中.但它不是一个好方法.如何刷新时如何将所选菜单的值传递给页面?这是突出显示菜单的代码

 $(document).ready(function () {
                var currentUrl = window.location.href;
                if (currentUrl.indexOf("home/welcome") !== -1) {
                    $("#home").parent().parent().addClass('menuHeaderActive');
                }
                else if (currentUrl.indexOf("EnergyCatagory/index") !== -1) {
                    $("#newtransaction").parent().parent().addClass('menuHeaderActive');
                }
                else if (currentUrl.indexOf("portfolio/Index") !== -1) {
                    $("#portfolio").parent().parent().addClass('menuHeaderActive');
                }
            });
Run Code Online (Sandbox Code Playgroud)

html javascript cookies jquery

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

如何在 ruby​​ on rails 中创建 json 对象?

我有一个任务要在 rils 上用 ruby​​ 做 jtable。这是我的控制器

 def list
    @students = Student.all
    @jtable = {'Result' => 'OK','Records' => @students.map(&:attributes)}

    respond_to do |format|
      format.html # index.html.erb
      format.json { render :json => @jtable}
    end
  end
def newstudent
    @student = Student.new
    @jtable = {'Result' => 'OK','Record' => @students.last(&:attributes)}
    respond_to do |format|
      format.html # new.html.erb
      format.json { render :json => @jtable }
    end
  end
Run Code Online (Sandbox Code Playgroud)

这是我的 index.html.erb 文件

<html>
    <head>
        <%=stylesheet_link_tag "jtable_blue","http://code.jquery.com/ui/1.9.1/themes/base/jquery-ui.css",:media => "all" %>
        <%= javascript_include_tag "jquery-1.8.3.min","http://code.jquery.com/ui/1.9.1/jquery-ui.js","jquery.jtable.min"%>
<script type="text/javascript">
    jQuery.noConflict();
    jQuery(document).ready(function () {
        jQuery('#StudentTableContainer').jtable({
            title: …
Run Code Online (Sandbox Code Playgroud)

ruby json ruby-on-rails-3.2

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

如何更改滚动条的颜色

我有任务来改变滚动条的颜色.为此,我使用了jscrollpane.By这样做只有浏览器滚动被更改.我想改变下拉列表的颜色.我怎么能这样做?HTML是

  <div class='columnLeft'>
       <div class="labels w110">
            <label>Country</label>
       </div>
       <div class="controls hello" id="hello">
            @Html.DropDownList("ddlReCountry", null, new { @onchange = "onReBindCountry()", @class = "dropdown w325" })
       </div>
  </div>
Run Code Online (Sandbox Code Playgroud)

javascript是

 $(function () {
            $('.hello ').jScrollPane();
            $('#hello').bind(
            'jsp-scroll-y',
        function (event, scrollPositionY, isAtTop, isAtBottom) {
            console.log('#pane1 Handle jsp-scroll-y', this,
                        'scrollPositionY=', scrollPositionY,
                        'isAtTop=', isAtTop,
                        'isAtBottom=', isAtBottom);
        });
 });
Run Code Online (Sandbox Code Playgroud)

css是

.jspTrack {
    background: lightgray !important;
}

.jspDrag {
    background: gray !important;
}
Run Code Online (Sandbox Code Playgroud)

javascript jquery jscrollpane css3

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

阻止ASP.NET Web应用程序/网站中的IP地址列表

我有一组IP地址.

部署我的应用程序后,我希望只能从特定的IP地址访问我的应用程序.

如何使用Global.asax(而不是通过IIS)实现此目的?

asp.net web-applications

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

如何将javascript对象的javascript值传递给ruby on rails中的控制器?

我有一个任务要在轨道上使用ruby做knockout.js.我想将javascript值发送给控制器.我的index.html.erb是

<%= javascript_include_tag "knockout-2.2.0","country-state" %>
<table>
    <thead>
        <tr>
            <th>Country</th>
            <th>State</th> 
            <th> </th>
        </tr>
    </thead>
    <tbody data-bind='foreach: lines'>
        <tr>
            <td>
                <select data-bind='options: sampleProductCategories, optionsText: "country", optionsCaption: "Select...", value: category'> </select>
            </td>
            <td data-bind="with: category">
                <select data-bind='options: products, optionsText: "country", optionsCaption: "Select...", value: $parent.product'> </select>
            </td>



            <td>
                <a href='#' data-bind='click: $parent.removeLine'>Remove</a>
            </td>
        </tr>
    </tbody>
</table>

<button data-bind='click: addLine'>Add</button>
<button data-bind='click: save'>Submit</button>

<script>
$(document).ready(function() {
function formatCurrency(value) {
    return "$" + value.toFixed(2);
}

var CartLine = function() {
    var self = this;
    self.category …
Run Code Online (Sandbox Code Playgroud)

ruby json ruby-on-rails ruby-on-rails-3.2

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

如何在jquery中将下拉设置为只读?

我想将下拉设置为只读.为此,我使用代码readonly="readonly".但它不能在asp.netmvc4中工作.我可以解决这个问题吗?请帮助

html javascript jquery asp.net-mvc-4

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

如何从给定文件夹中获取图像文件名

我有一个任务是使用jquery显示文件夹中的所有图像.

为此,我使用了代码

var imageFolder = '../../Images/Avatar/';
var imgsrc = imageFolder +'';
Run Code Online (Sandbox Code Playgroud)

我需要在该文件夹头像中获取图像文件名.我怎样才能获得文件名.该头像文件夹中有很多图像文件也有一些txt文件.我只需要jpg,png,gif图像.

html javascript jquery

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

如何在文件上传时显示文件名

我想在上传文件时显示文件名。为此我使用了隐藏字段。我的代码是

<label>File</lable>
<input type="image" src="http://upload.wikimedia.org/wikipedia/commons/c/ca/Button-Lightblue.svg" width="30px"/>
<input type="file" id="my_file" style="display: none;" />
Run Code Online (Sandbox Code Playgroud)

javascript是

$("input[type='image']").click(function() {
    $("input[id='my_file']").click();
});
Run Code Online (Sandbox Code Playgroud)

我怎样才能做到这一点?

html javascript css jquery

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

keypress在Mozila Firefox中不起作用

我有一个任务来限制字母值的文本框.只有浮点值才有可能.在十进制之后我们必须写出两位数.我这样做但它在Mozilla Firefox中不起作用.我怎么解决这个问题?

我的剧本是

$(function () {
    $('#name').bind('paste', function () {
        var self = this;
        setTimeout(function () {
            if (!/^[a-zA-Z]+$/.test($(self).val())) $(self).val('');
        }, 0);
    });

    $('#salary').bind('paste', function () {
        var self = this;
        setTimeout(function () {
            if (!/^\d*(\.\d{1,2})+$/.test($(self).val())) $(self).val('');
        }, 0);
    });

    $('.decimal').keypress(function (e) {
        var character = String.fromCharCode(e.keyCode)
        var newValue = this.value + character;
        if (isNaN(newValue) || hasDecimalPlace(newValue, 3)) {
            e.preventDefault();
            return false;
        }
    });

    function hasDecimalPlace(value, x) {
        var pointIndex = value.indexOf('.');
        return  pointIndex >= 0 && pointIndex < value.length …
Run Code Online (Sandbox Code Playgroud)

html javascript jquery

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

如何为链接设置动态ID?

我有一个水平菜单.我想使用jQuery为每个创建一个id.我的代码是:

<div class="menuBar">
    <div class="menuHeader ui-corner-top">
        <span><a href="#" onclick="Home()">Home</a></span>
    </div>
    <div class="menuHeader ui-corner-top">
        <span><a href="#" onclick="NewTransaction()" id="menu2">New Transaction</a></span>
    </div>
</div>
Run Code Online (Sandbox Code Playgroud)

这里的菜单没有id.我想使用jQuery动态创建id.我怎样才能做到这一点?我做了一个这样的例子,但它不起作用:

var i = 0;
$('.menuHeader').each(function () {
    i++;
    newID = menu + i;
    $(this).attr('id', newID);
    $(this).val(i);
});
Run Code Online (Sandbox Code Playgroud)

html javascript jquery

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