dougong7850 2014-07-27 18:01
浏览 234
已采纳

如何用php代码构建<input>设置值属性

I'm not sure how word my question clearly, so here's what I'm trying to do with no success so far (simplified code)

The end result I need on the page is:

<input type="text" class="form-control" id="Colour" name="InputName7" value="<?php echo $InputName7 ; ?>">

I have a function to build this but the value attribute is rendering as a string instead of code... and I end up with "" as the string value. I don't understand why.

Here's how I call the function:

$newItem = SetItemInputTag("Colour", $ItemCount, "<?php echo $InputName7; ?>", FALSE)

Here's function:

function SetItemInputTag($TagId, $ItemCount, $TagValue, $Disabled){
 $InputTag = "<input type='text' class='form-control' id='" . $TagId . "' name= 'InputName" . $ItemCount . "' disabled value='" . $TagValue . "'>";

  return $InputTag;
}

I appreciate any help I can get!!

  • 写回答

4条回答 默认 最新

  • dongli7870 2014-07-27 18:07
    关注

    I think you just need to use this much .

    $newItem = SetItemInputTag("Colour", $ItemCount, $InputName7, FALSE);
    

    instead of this line

    $newItem = SetItemInputTag("Colour", $ItemCount, "<?php echo $InputName7; ?>", FALSE)
    

    this is because you are already in php. then why don't you using script-lets in your code inside your function call.just remove that and try.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥30 python代码,帮调试,帮帮忙吧
  • ¥15 #MATLAB仿真#车辆换道路径规划