单击按钮提交数据库中 div 的内容

Submit content of div in database on button click

我有一个所见即所得的工具,可以用来创建内容。在底部,我有一个表单,我可以在其中向数据库提交一个值(来自输入文本)。那很好用。现在,我正在尝试提交数据库中所见即所得的内容。

我正在考虑在输入中使用一个值,如下所示:

<input name="videoLink" type="text"  value="John" required/>

并使用 javascript 使值动态化。但必须有更简单的方法。使表单提交 div 的内容,而不必在输入框中键入任何内容。

我的代码如下所示:

angular.module("textAngularTest", ['textAngular']);

function wysiwygeditor($scope) {
  $scope.orightml = '<h2>Put Your Text Here</h2>';
  $scope.htmlcontent = $scope.orightml;
  $scope.disabled = false;
};
.ta-editor {
  min-height: 80px;
  height: auto;
  overflow: auto;
  font-family: inherit;
  font-size: 100%;
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.4/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.4/angular-sanitize.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/textAngular/1.1.2/textAngular.min.js"></script>
<link href="https://netdna.bootstrapcdn.com/bootstrap/3.0.1/css/bootstrap.min.css" rel="stylesheet" />
<link href="https://netdna.bootstrapcdn.com/font-awesome/4.0.0/css/font-awesome.min.css" rel="stylesheet" />
<div ng-app="textAngularTest" ng-controller="wysiwygeditor" class="container app">
  <h3>WYSIWYG Editor</h3>
  <div text-angular="text-angular" name="htmlcontent" ng-model="htmlcontent" ta-disabled='disabled'></div>
  <!--<h3>Raw HTML in a text area</h3>
    <textarea ng-model="htmlcontent" style="width: 100%"></textarea>-->
  <h3>Preview</h3>
  <div ng-bind-html="htmlcontent"></div>
  <!--<h3>Bound with ta-bind, our internal html-binding directive</h3>
    <div ta-bind="text" ng-model="htmlcontent" ta-readonly='disabled'></div>-->
  <button type="button" ng-click="htmlcontent = orightml">Reset</button>

  <form action="Insert.php" method='POST' enctype='multipart/form-data'>
    <label><input name="videoLink" type="text" required/></label>
    <input id="button" type="submit" name="log">
  </form>


</div>

使用 placeholder 而不是 value。 设置值 =" " 但 placeholder="Put text here" ... 否则你会得到很多 Johns.. 我想这就是你想要避免的?我不认为你可以避免 php/ 将值从 html 传递给 php [使用 javascript] 将值输入数据库。

你的表格没有那么大。除非您的站点使用 CMS 所有页面中包含的 angular/is,否则您不需要那么多的 js。因此,如果问题确实是 如何以最小的 javascript 将变量传递给 php,那么请发表评论。

您仍应使用占位符而不是值。否则,如果人们不更改文本/可能只是按 enter/submit.. 你的 required 错误消息将不会触发。数据库中有很多 Johns! :)

希望对您有所帮助