小编tec*_*t82的帖子

克隆/删除输入字段 - 保持元素ID唯一

我目前正在处理在表单内生成动态输入字段.我有一个复杂的例子,它使用复选框和选择框.它有两种类型的元素:main_itemssub_items.如上所述,我可以通过一个clone函数动态添加输入字段,该函数复制具有唯一id属性的一组新输入字段.但是我对两件事情有很大的困难:首先,保持id每个复制元素的独特性,特别是对于选择框.其次,我只能得到第一个下拉菜单才能用于第一个项目,但我还没有想出办法为其他项目做这个.的jsfiddle

$('#btnAdd').click(function () {
    var num = $('.clonedSection').length;
    var newNum = num + 1;

    var newSection = $('#pq_entry_' + num).clone().attr('id', 'pq_entry_' + newNum);
    newSection.find('input[type="text"]').val('');
    newSection.find('select').val('');
    newSection.find('input[type="checkbox"]').prop('checked', false);
    //hide sub item
    newSection.find('.sub-item').hide();

    //change the input element selectors to use name
    newSection.find('input[name^="first_item_"]').attr('id', 'main_item_' + newNum).attr('name', 'main_item_' + newNum);
    newSection.find('input[name^="second_item_"]').attr('id', 'second_item_' + newNum).attr('name', 'second_item_' + newNum);
    newSection.find('input[name^="item_count_"]').attr('id', 'item_count_' + newNum).attr('name', 'item_count_' + newNum);
    newSection.find('input[name^="sub_item_"]').attr('id', 'sub_item_' + newNum).attr('name', 'sub_item_' + newNum);
    newSection.find('input[name^="other_item_"]').attr('id', 'other_item_' + newNum).attr('name', …
Run Code Online (Sandbox Code Playgroud)

javascript jquery

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

正则表达式:从URL中剥离Youtube视频的ID

我目前正在使用正则表达式代码来分隔YT视频ID.我使用正则表达式的原因是,视频网址的格式有很多种.我已经构建了一个正则表达式,它几乎可以检测几乎所有YT url格式的ID,除了下面的那个.我试过修改但没有运气.有没有办法让Regex从下面的URL中删除id?

http://www.youtube.com/watch?feature=v-feature&v=317a815FLWQ

正则表达式:

('~https?://(?:[0-9A-Z-]+\.)?(?:youtu\.be/| youtube\.com\S*[^\w\-\s])([\w\-]{11})(?=[^\w\-]|$)(?![?=&+%\w]*(?:[\'"][^<>]*>| </a>))[?=&+%\w]*~ix','http://www.youtube.com/watch?v=$1',$url);
Run Code Online (Sandbox Code Playgroud)

regex youtube

5
推荐指数
0
解决办法
853
查看次数

Javascript:使用复选框值显示图像

我目前正在使用单选按钮和复选框,以借助javascript显示图像.具体来说:我在处理复选框和显示图像时遇到了问题.使用单选按钮,将只显示该类别的一个图像.但是对于复选框,需要显示多个图像.例如,用户可以检查夹克和手套的字段,并且将显示两个图片.

单击复选框时,如何格式化功能以显示多张图片?

JS

<script language="JavaScript" type="text/javascript">

function check_value(val, id, type) {     
    var el = document.getElementById("imgBox" + id);
    if (val>0 && val<4) { //will trigger when [1,2,3]
       el.src = "images/"+ type + val + ".jpg";
       el.style.display = "";
  }    
  }      

</script>
Run Code Online (Sandbox Code Playgroud)

HTML

<h2>Choose a bike</h2>
<form name="builder">
    <input type="radio" name="field" value="1" onclick='check_value(1, 1, "bike")'/> KAWASAKI KX 450F<br />
    <input type="radio" name="field" value="2" onclick='check_value(2, 1, "bike")'/> 2010 Yamaha Road Star S<br />
    <input type="radio" name="field" value="3" onclick='check_value(3, 1, "bike")'/> Aprilia RSV4<br …
Run Code Online (Sandbox Code Playgroud)

javascript

5
推荐指数
0
解决办法
1013
查看次数

功能:计算速度,时间,距离(双重型变量)

我已经创建了一个按下计算按钮的程序,平均速度将使用总行驶距离和行驶总小时数来计算,并且将乘以从纽约市到迈阿密的距离来获取距离纽约市到迈阿密.单击按钮Label1后将报告速度,时间和距离,Clear_textBox()并清除所有文本框字段.问题是我没有得到任何结果但错误.

有人可以指导我在我的代码中进行更改吗?

我收到错误Display_Results和属性的函数private double get_Time

   namespace form1
   {
public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }



    private double Calculate_Velocity()
    {
        //Calculate Velocity
        int startingMileageBox;
        startingMileageBox = Convert.ToInt32(textBox1.Text);

        int endingMileageBox;
        endingMileageBox = Convert.ToInt32(textBox2.Text);

        double time = Get_Time(); //assuming you have set up GetTime()
        double distance = endingMileageBox - startingMileageBox;
        return distance / time; 
    }

   public double Get_Time()
    {
        //Get Time
        return get_Time;
    }

    private double Calculate_Distance(double velocity, double time)
    { …
Run Code Online (Sandbox Code Playgroud)

c#

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

复选框:一次只允许一个复选框

我目前正在使用复选框并根据所选值显示值.几乎所有东西都在工作,除了我必须复选框method of shipping.现在,用户可以选择两种方式,这是一个问题.有没有办法只允许检查一个复选框method of shipping

JS

<script>
function check_value(currentElement, val, id, type) {
    var el = document.getElementById("imgBox" + id);
    if (val > 0 && val < 4) { //will trigger when [1,2,3]

        if(currentElement.checked)
        {
            el.src = "images/" + type + val + ".jpg";
            el.style.display = "";
        }
        else
        {
            el.src = "";
            el.style.display = "none";
        }

    }
}    
</script>
Run Code Online (Sandbox Code Playgroud)

HTML

<h2>Choose method of shipping</h2>
<form name="shipping_list">
    <input type="checkbox" name="shipping1" onclick='check_value(this, 1, "4", "shipping")'/> USPS Ground<br …
Run Code Online (Sandbox Code Playgroud)

javascript

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

在PictureBox上绘制网格

我目前正在使用pictureBox.我很难在图片框上画一个大约2 x 2正方形的网格.现在,下面的代码只给我一条画线.我怎样才能在pictureBox上绘制一个完整的网格?

码:

private Graphics g1;

    public Form1()
    {
        InitializeComponent();


        pictureBox1.Image = new Bitmap(500, 500);
        g1 = Graphics.FromImage(this.pictureBox1.Image);
        Pen gridPen = new Pen(Color.Black, 2);
        g1.DrawLine(gridPen, 0, 0, 100, 100);

    }
Run Code Online (Sandbox Code Playgroud)

这就是我想要完成的事情: 在此输入图像描述

c#

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

无法将类型隐式转换为“字符串”错误

我目前正在处理显示项目列表。我创建了一个GetNextItem返回obj1. 当我从 调用该方法时,出现buttonClick以下错误:

Cannot implicitly convert type 'TreeFarm.Form1.fruit_trees' to 'string'.
Run Code Online (Sandbox Code Playgroud)

不知道为什么要这样做。

public items_list GetNextItem()
{
    items_list obj1 = this.current_item;
    if (obj1 != null)
    {
        current_item = current_item.next_item;
    }
    return obj1;
}

ListForItems mainlist = new ListForItems();
private void ShowNextItem_Click(object sender, EventArgs e)
{

    labelSpecificItem.Text = mainlist.GetNextItem();         
}
Run Code Online (Sandbox Code Playgroud)

c#

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

将十进制转换为二进制,但采用8位格式

可能重复:
如何用零填充二进制字符串?

我能够将十进制数转换为二进制数,但不能转换为8位格式.例如,如果我输入5的结果是101正确的但是如何以8位格式显示结果,例如00000101

string result = Convert.ToString(num, 2).PadLeft(8, '0');
Run Code Online (Sandbox Code Playgroud)

c#

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

从URL链接中隔离数字ID

我正在浏览stackoverflow,并在此处找到了一个很棒的正则表达式代码.可能还有其他方法可以隔离youtube视频ID,但我选择使用正则表达式进行学习.带有input1(如下所示)的正则表达式代码忽略了&字符后的所有内容.这会清除视频ID,从而提供错误或空ID结果.为什么正则表达式会在之后清除所有内容&

错误:

输入1:http://www.youtube.com/watch? feature&v = 317a815FLWQ

结果1:http // www.youtube.com/watch?功能

正常:

输入2:http://www.youtube.com/watch? v = spDj54kf-vY&feature = g-vrec

结果2:http://www.youtube.com/watch? v = spDj54kf-vY

正则表达式代码(附原文注释)

$text = preg_replace('~
        # Match non-linked youtube URL in the wild. (Rev:20111012)
        https?://         # Required scheme. Either http or https.
        (?:[0-9A-Z-]+\.)? # Optional subdomain.
        (?:               # Group host alternatives.
          youtu\.be/      # Either youtu.be,
        | youtube\.com    # or youtube.com followed by …
Run Code Online (Sandbox Code Playgroud)

php regex

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

Php json编码 - json对象的特定格式

我目前正在使用第三方API.我有一些困难将我的db值格式化为json对象.如果它们处于某种格式,api会获取值.在下面的PHP代码中,我使用foreach循环来获取结果.然后array_push将值放在数组中.我正在获取字符串数据而不是数字coordinates.最后,我没有得到理想的结果.如何将json对象格式化为如下例所示?

目前的结果:

{
coordinates: [
"-121.2808, 38.3320"
],
attributes: "Sacramento"
},
Run Code Online (Sandbox Code Playgroud)

期望的结果:

{
    coordinates: [-121.2808, 38.3320],
    attributes: {
        name: 'Sacramento'
    }
},
Run Code Online (Sandbox Code Playgroud)

PHP循环和json_encode

header("Content-type: application/json");
//get the course list
$location_query = $db_con->prepare("SELECT city, X(location) as latitude, Y(location) as longitude
FROM company
");
$location_query->execute();
$data = $location_query->fetchAll();
$output = array();
foreach ($data as $row) {
    array_push($output, array('coordinates'=>array($row["latitude"].",".$row["longitude"]), 'attributes'=>$row["city"]));


}// foreach ($data as $row) {
echo json_encode($output);
Run Code Online (Sandbox Code Playgroud)

php arrays json

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

标签 统计

c# ×4

javascript ×3

php ×2

regex ×2

arrays ×1

jquery ×1

json ×1

youtube ×1