add_questions.blade.php 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <div class="form-group"></div>
  2. <div class="form-group">
  3. <label class="col-xs-12 col-sm-3 col-md-1 control-label">添加问题</label>
  4. <div class="col-xs-12 col-sm-3 col-md-2">
  5. <select class="form-control tpl-category-parent" id="choice" name="">
  6. <option value="1">单选</option>
  7. <option value="2">多选</option>
  8. </select>
  9. </div>
  10. <div class="col-xs-12 col-sm-3 col-md-2 input-group-btn">
  11. <a class="btn btn-primary btn-add-type" href="javascript:;" onclick="appendText();"><i id="add_field" class="fa fa-plus" title=""></i> 增加一个字段</a>
  12. </div>
  13. </div>
  14. <div class="form-group"></div>
  15. <table class="table">
  16. <thead>
  17. <tr>
  18. <th style="width:52px;text-align: right">类型</th>
  19. <th style="width:50px;text-align: center">排序</th>
  20. <th style="width:200px;text-align: center">名称</th>
  21. <th style="width:50px;text-align: center">必填 </th>
  22. <th style="width:550px;">设置</th>
  23. </tr>
  24. </thead>
  25. <tbody id="type-items">
  26. </tbody>
  27. </table>
  28. <script language='javascript'>
  29. var num =0;
  30. var answer = 0;
  31. function appendText() {
  32. var type = $("#choice").val();
  33. if(type == 1){
  34. var name = '单选';
  35. }else{
  36. var name = '多选';
  37. }
  38. var option = '<tr style="border-top: hidden" id="problem_'+num+'">' +
  39. '<td style="width:52px; text-align: right;">' +
  40. '<input type="hidden" class="form-control" name="data[option]['+num+'][type]" value="'+type+'" placeholder="">' +
  41. '<sapn >'+name+'</span></td>' +
  42. '<td style="width:50px; text-align: center;">' +
  43. '<input type="text" class="form-control" name="data[option]['+num+'][sort]" value="" style="text-align: center;" placeholder=""></td>' +
  44. '<td style="width:100%;text-align: center;">' +
  45. '<input type="text" class="form-control" name="data[option]['+num+'][choice_title]" value="" ></td>' +
  46. '<td style="width:20px;text-align: center;">' +
  47. '<input type="checkbox" name="data[option]['+num+'][required]" value="1" ></td>' +
  48. '<td style="width:52px;"> ' +
  49. '<div class="col-sm-12 col-md-12" id="answer_'+num+'"></div>'+
  50. '<div class="col-sm-12 col-md-12"><a class="btn btn-primary btn-add-type" href="javascript:;" onclick="appendOption('+num+');">' +
  51. '<i id="add_field" class="fa fa-plus" title=""></i> 添加选项</a></div></div></td>' +
  52. '<td><a class="btn btn-default nav-del" href="javascript:;" onclick="problemClosed('+num+');">' +
  53. ' <i id="add_field" class="fa fa-times" title=""></i> </a></td>'+
  54. '</tr>';
  55. $("#type-items").append(option);
  56. num++
  57. }
  58. function appendOption(num) {
  59. console.log(num)
  60. var answer_option = '<ul id="an_'+answer+'">' +
  61. '<li class="col-sm-12 col-md-5">' +
  62. '<input type="text" class="form-control" name="data[option]['+num+'][choice][answer]['+answer+']" value="" style="text-align: center;" placeholder=""></li>' +
  63. '<li class="col-sm-12 col-md-5"> <div class="input-group">'+
  64. ' <input type="text" name="data[option]['+num+'][choice][fraction]['+answer+']" class="form-control discounts_value" value=""/>'+
  65. ' <div class="input-group-addon waytxt">分</div></div></li>'+
  66. '<a class="btn btn-default nav-del" style="border:none!important;" href="javascript:;" onclick="Closed('+answer+');">'+
  67. ' <i id="add_field" class="fa fa-times" title=""></i> </a>'+
  68. '</ul>';
  69. $("#"+"answer_"+num).append(answer_option);
  70. answer++
  71. }
  72. function problemClosed(num) {
  73. $("#"+"problem_"+num).empty();
  74. }
  75. function Closed(answer) {
  76. $("#"+"an_"+answer).empty();
  77. }
  78. </script>