如何获取所选复选框的值以及该复选框的输入文本值?

时间:2016-08-22 09:24:41

标签: javascript jquery html checkbox

我有一个复选框列表,旁边是每个复选框的输入文本。如果未选中该复选框,则禁用输入文本,该文本正常工作。我想获取已选中的复选框的值以及用户为该特定复选框提供的输入。我可以获得复选复选框的值,问题是得到输入文本的值。

例如:

  1. CHECKBOX - 如果未选中则禁用输入文字

  2. INPUTTEXT - 如果选中复选框,则用户可以输入数据。

  3. 我怎样才能做到这一点。您的帮助在高级

    中得到了认可

    这是我的[code][https://jsfiddle.net/JayStar/x5u1gyod/]

1 个答案:

答案 0 :(得分:1)

像这样使用

public partial class MainWindow : Window
{

    private DispatcherOperation _action;
    private int _width = 2000;
    private int _height = 1000;
    private double _top;

    public MainWindow()
    {
        InitializeComponent();
        Dispatcher.Hooks.OperationCompleted += HooksOnOperationCompleted;
    }

    private void HooksOnOperationCompleted(object sender, DispatcherHookEventArgs dispatcherHookEventArgs)
    {
        if(dispatcherHookEventArgs.Operation != _action) return;
        _action.Task.ContinueWith((t) =>
        {
            Rectangle rect = new Rectangle(0, 0, _width, _height);
            Bitmap bmp = new Bitmap(rect.Width, rect.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
            Graphics g = Graphics.FromImage(bmp);
            g.CopyFromScreen(rect.Left, rect.Top, 0, 0, bmp.Size, CopyPixelOperation.SourceCopy);
            bmp.Save("help" + DateTime.Now.Ticks + ".jpg", ImageFormat.Jpeg);
        }).ContinueWith(t =>
        {
            Dispatcher.BeginInvoke((Action)(() =>
            {
                Top = _top;
            }));
        });


    }

    private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
    {
        _top = Top;
        _action = Dispatcher.BeginInvoke((Action) (() =>
        {
            Top = 10000;
        }));
    }
}
// Returns an array with values of the selected (checked) checkboxes in "frm"
function getSelectedChbox(frm) {
  var selchbox = [];        // array that will store the value of selected checkboxes

  // gets all the input tags in frm, and their number
  var inpfields = frm.getElementsByTagName('input');
  var nr_inpfields = inpfields.length;

  // traverse the inpfields elements, and adds the value of selected (checked) checkbox in selchbox
  for(var i=0; i<nr_inpfields; i++) {
    if(inpfields[i].type == 'checkbox' && inpfields[i].checked == true) {
    console.log(inpfields[i].id);
    var textboxVal = document.getElementById(inpfields[i].id+"code").value;
console.log(textboxVal);
    var obj = {checkbox:inpfields[i].value,textbox:textboxVal};
    	selchbox.push(obj);
    }			
  }
  return selchbox;
}
  /* Test this function */
// When click on #langtest, alert the selected values
document.getElementById('langtest').onclick = function(){
  var selchb = getSelectedChbox(this.form);     // gets the array returned by getSelectedChbox()
  alert(JSON.stringify(selchb));
}



//Check if checkbox is checked, if not checked disable input text
 document.getElementById('html').onchange = function() {
    document.getElementById('htmlcode').disabled = !this.checked;
  };
  document.getElementById('css').onchange = function() {
    document.getElementById('csscode').disabled = !this.checked;
  };
  document.getElementById('javascript').onchange = function() {
    document.getElementById('javascriptcode').disabled = !this.checked;
  };
  document.getElementById('php').onchange = function() {
    document.getElementById('phpcode').disabled = !this.checked;
  };
  document.getElementById('python').onchange = function() {
    document.getElementById('pythoncode').disabled = !this.checked;
  };
  document.getElementById('net').onchange = function() {
    document.getElementById('netcode').disabled = !this.checked;
  };
  document.getElementById('mysql').onchange = function() {
    document.getElementById('mysqlcode').disabled = !this.checked;
  };

//-->
 .programminglanguage{
    width        :   auto;
    height       :   auto;  
    margin-left  :   19%;
    margin-right :   18%;
    margin-top   :   2%;
  }
  .programming{
    margin-left: 10%;
  }